diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/data/hdcp1x.mdd b/XilinxProcessorIPLib/drivers/hdcp1x/data/hdcp1x.mdd index 374e89a3..22772ad6 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/data/hdcp1x.mdd +++ b/XilinxProcessorIPLib/drivers/hdcp1x/data/hdcp1x.mdd @@ -18,8 +18,8 @@ # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - # XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + # XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/data/hdcp1x.tcl b/XilinxProcessorIPLib/drivers/hdcp1x/data/hdcp1x.tcl index d6f4b0ec..079d39ff 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/data/hdcp1x.tcl +++ b/XilinxProcessorIPLib/drivers/hdcp1x/data/hdcp1x.tcl @@ -18,8 +18,8 @@ # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - # XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + # XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/Makefile b/XilinxProcessorIPLib/drivers/hdcp1x/src/Makefile index cd17ff37..b3e9a59b 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/Makefile +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/Makefile @@ -9,7 +9,7 @@ RELEASEDIR=../../../lib INCLUDEDIR=../../../include INCLUDES=-I./. -I${INCLUDEDIR} -INCLUDEFILES=xhdcp1x.h xhdcp1x_port.h +INCLUDEFILES=xhdcp1x.h xhdcp1x_hw.h xhdcp1x_port.h LIBSOURCES=*.c OUTS = *.o diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x.c index 4eeccfe4..46578495 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -29,7 +29,6 @@ * this Software without prior written authorization from Xilinx. * ******************************************************************************/ - /*****************************************************************************/ /** * @@ -42,13 +41,13 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. -* 1.01 07/23/15 Additional documentation and formating +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ /***************************** Include Files *********************************/ + #include #include #include "xhdcp1x.h" @@ -62,15 +61,16 @@ #include "xstatus.h" /************************** Constant Definitions *****************************/ + #if defined(XPAR_XHDMI_TX_NUM_INSTANCES) && (XPAR_XHDMI_TX_NUM_INSTANCES > 0) - #define INCLUDE_TX +#define INCLUDE_TX #endif #if defined(XPAR_XHDMI_RX_NUM_INSTANCES) && (XPAR_XHDMI_RX_NUM_INSTANCES > 0) - #define INCLUDE_RX +#define INCLUDE_RX #endif #if defined(XPAR_XDP_NUM_INSTANCES) && (XPAR_XDP_NUM_INSTANCES > 0) - #define INCLUDE_RX - #define INCLUDE_TX +#define INCLUDE_RX +#define INCLUDE_TX #endif /** @@ -83,99 +83,88 @@ /************************** Extern Declarations ******************************/ /************************** Global Declarations ******************************/ -XHdcp1x_Printf XHdcp1xDebugPrintf = NULL; -XHdcp1x_LogMsg XHdcp1xDebugLogMsg = NULL; -XHdcp1x_KsvRevokeCheck XHdcp1xKsvRevokeCheck = NULL; -XHdcp1x_TimerStart XHdcp1xTimerStart = NULL; -XHdcp1x_TimerStop XHdcp1xTimerStop = NULL; -XHdcp1x_TimerDelay XHdcp1xTimerDelay = NULL; + +XHdcp1x_Printf XHdcp1xDebugPrintf = NULL; +XHdcp1x_LogMsg XHdcp1xDebugLogMsg = NULL; +XHdcp1x_KsvRevokeCheck XHdcp1xKsvRevokeCheck = NULL; +XHdcp1x_TimerStart XHdcp1xTimerStart = NULL; +XHdcp1x_TimerStop XHdcp1xTimerStop = NULL; +XHdcp1x_TimerDelay XHdcp1xTimerDelay = NULL; /***************** Macros (Inline Functions) Definitions *********************/ /*****************************************************************************/ /** +* This queries an interface to determine if it is a receiver. * -* This queries an interface to determine if it is a receiver +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating receiver (TRUE) or not (FALSE). * -* @return -* Truth value indicating receiver (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ -#define IsRX(InstancePtr) (InstancePtr->Common.CfgPtr->IsRx) +#define IsRX(InstancePtr) ((InstancePtr)->Common.CfgPtr->IsRx) /*****************************************************************************/ /** +* This queries an interface to determine if it is a transmitter. * -* This queries an interface to determine if it is a transmitter +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating transmitter (TRUE) or not (FALSE). * -* @return -* Truth value indicating transmitter (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ -#define IsTX(InstancePtr) (!InstancePtr->Common.CfgPtr->IsRx) +#define IsTX(InstancePtr) (!(InstancePtr)->Common.CfgPtr->IsRx) /*****************************************************************************/ /** +* This queries an interface to determine if it is Display Port (DP). * -* This queries an interface to determine if it is Display Port (DP) +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating DP (TRUE) or not (FALSE). * -* @return -* Truth value indicating DP (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ -#define IsDP(InstancePtr) (!InstancePtr->Common.CfgPtr->IsHDMI) +#define IsDP(InstancePtr) (!(InstancePtr)->Common.CfgPtr->IsHDMI) /*****************************************************************************/ /** +* This queries an interface to determine if it is HDMI. * -* This queries an interface to determine if it is HDMI +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating HDMI (TRUE) or not (FALSE). * -* @return -* Truth value indicating HDMI (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ -#define IsHDMI(InstancePtr) (InstancePtr->Common.CfgPtr->IsHDMI) +#define IsHDMI(InstancePtr) ((InstancePtr)->Common.CfgPtr->IsHDMI) /************************** Function Definitions *****************************/ /*****************************************************************************/ /** +* This function retrieves the configuration for this HDCP instance and fills +* in the InstancePtr->Config structure. * -* This function determines the adaptor for a specified port device -* -* @param InstancePtr the device whose adaptor is to be determined -* @param CfgPtr the configuration of the instance -* @param PhyIfPtr pointer to the underlying physical interface +* @param InstancePtr is the device whose adaptor is to be determined. +* @param CfgPtr is the configuration of the instance. +* @param PhyIfPtr is pointer to the underlying physical interface. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_CfgInitialize(XHdcp1x *InstancePtr, const XHdcp1x_Config *CfgPtr, - void* PhyIfPtr) + void *PhyIfPtr) { int Status = XST_SUCCESS; @@ -219,16 +208,15 @@ int XHdcp1x_CfgInitialize(XHdcp1x *InstancePtr, const XHdcp1x_Config *CfgPtr, /*****************************************************************************/ /** +* This function polls an HDCP interface. * -* This function polls an hdcp interface -* -* @param InstancePtr the interface to poll +* @param InstancePtr is the interface to poll. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_Poll(XHdcp1x *InstancePtr) @@ -261,16 +249,15 @@ int XHdcp1x_Poll(XHdcp1x *InstancePtr) /*****************************************************************************/ /** +* This function resets an HDCP interface. * -* This function resets an hdcp interface -* -* @param InstancePtr the interface to reset +* @param InstancePtr is the interface to reset. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_Reset(XHdcp1x *InstancePtr) @@ -303,16 +290,15 @@ int XHdcp1x_Reset(XHdcp1x *InstancePtr) /*****************************************************************************/ /** +* This function enables an HDCP interface. * -* This function enables an hdcp interface -* -* @param InstancePtr the interface to enable +* @param InstancePtr is the interface to enable. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_Enable(XHdcp1x *InstancePtr) @@ -345,16 +331,15 @@ int XHdcp1x_Enable(XHdcp1x *InstancePtr) /*****************************************************************************/ /** +* This function disables an HDCP interface. * -* This function disables an hdcp interface -* -* @param InstancePtr the interface to disable +* @param InstancePtr is the interface to disable. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_Disable(XHdcp1x *InstancePtr) @@ -387,17 +372,16 @@ int XHdcp1x_Disable(XHdcp1x *InstancePtr) /*****************************************************************************/ /** +* This function updates the state of the underlying physical interface. * -* This function updates the state of the underlying physical interface -* -* @param InstancePtr the interface to update -* @param IsUp truth value indicating the underlying physical interface state +* @param InstancePtr is the interface to update. +* @param IsUp indicates the state of the underlying physical interface. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_SetPhysicalState(XHdcp1x *InstancePtr, int IsUp) @@ -430,17 +414,16 @@ int XHdcp1x_SetPhysicalState(XHdcp1x *InstancePtr, int IsUp) /*****************************************************************************/ /** -* * This function sets the lane count of a hdcp interface * -* @param InstancePtr the interface to update -* @param LaneCount the lane count +* @param InstancePtr is the interface to update. +* @param LaneCount is the lane count. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_SetLaneCount(XHdcp1x *InstancePtr, int LaneCount) @@ -473,16 +456,15 @@ int XHdcp1x_SetLaneCount(XHdcp1x *InstancePtr, int LaneCount) /*****************************************************************************/ /** +* This function initiates authentication of an HDCP interface. * -* This function initiates authentication of an hdcp interface -* -* @param InstancePtr the interface to initiate authentication on +* @param InstancePtr is the interface to initiate authentication on. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_Authenticate(XHdcp1x *InstancePtr) @@ -515,17 +497,15 @@ int XHdcp1x_Authenticate(XHdcp1x *InstancePtr) /*****************************************************************************/ /** -* * This function queries an interface to determine if authentication is in -* progress +* progress. * -* @param InstancePtr the interface to query +* @param InstancePtr is the interface to query. * -* @return -* Truth value indicating authentication in progress (TRUE) or not (FALSE) +* @return Truth value indicating authentication in progress (TRUE) or not +* (FALSE). * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_IsInProgress(const XHdcp1x *InstancePtr) @@ -547,17 +527,14 @@ int XHdcp1x_IsInProgress(const XHdcp1x *InstancePtr) /*****************************************************************************/ /** -* * This function queries an interface to determine if it has successfully -* completed authentication +* completed authentication. * -* @param InstancePtr the interface to query +* @param InstancePtr is the interface to query. * -* @return -* Truth value indicating authenticated (TRUE) or not (FALSE) +* @return Truth value indicating authenticated (TRUE) or not (FALSE). * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_IsAuthenticated(const XHdcp1x *InstancePtr) @@ -590,17 +567,14 @@ int XHdcp1x_IsAuthenticated(const XHdcp1x *InstancePtr) /*****************************************************************************/ /** -* * This function retrieves the current encryption map of the video streams -* traversing an hdcp interface +* traversing an hdcp interface. * -* @param InstancePtr the interface to query +* @param InstancePtr is the interface to query. * -* @return -* The current encryption map +* @return The current encryption map. * -* @note -* None. +* @note None. * ******************************************************************************/ u64 XHdcp1x_GetEncryption(const XHdcp1x *InstancePtr) @@ -633,18 +607,16 @@ u64 XHdcp1x_GetEncryption(const XHdcp1x *InstancePtr) /*****************************************************************************/ /** +* This function enables encryption on a series of streams within an HDCP +* interface. * -* This function enables encryption on a series of streams within an hdcp -* interface +* @param InstancePtr is the interface to configure. +* @param Map is the stream map to enable encryption on. * -* @param InstancePtr the interface to configure -* @param Map the stream map to enable encryption on +* @return XST_SUCCESS if successful. +* XST_FAILURE otherwise. * -* @return -* XST_SUCCESS if successful -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_EnableEncryption(XHdcp1x *InstancePtr, u64 Map) @@ -666,18 +638,17 @@ int XHdcp1x_EnableEncryption(XHdcp1x *InstancePtr, u64 Map) /*****************************************************************************/ /** +* This function disables encryption on a series of streams within an HDCP +* interface. * -* This function disables encryption on a series of streams within an hdcp -* interface -* -* @param InstancePtr the interface to configure -* @param Map the stream map to disable encryption on +* @param InstancePtr is the interface to configure. +* @param Map is the stream map to disable encryption on. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_DisableEncryption(XHdcp1x *InstancePtr, u64 Map) @@ -699,18 +670,17 @@ int XHdcp1x_DisableEncryption(XHdcp1x *InstancePtr, u64 Map) /*****************************************************************************/ /** +* This function sets the key selection vector that is to be used by the HDCP +* cipher. * -* This function sets the key selection vector that is to be used by the hdcp -* cipher -* -* @param InstancePtr the interface to configure -* @param KeySelect the key selection vector +* @param InstancePtr is the interface to configure. +* @param KeySelect is the key selection vector. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_SetKeySelect(XHdcp1x *InstancePtr, u8 KeySelect) @@ -749,16 +719,13 @@ int XHdcp1x_SetKeySelect(XHdcp1x *InstancePtr, u8 KeySelect) /*****************************************************************************/ /** +* This function handles a timeout on an HDCP interface. * -* This function handles a timeout on an hdcp interface +* @param InstancePtr is the interface. * -* @param InstancePtr the interface +* @return None. * -* @return -* void -* -* @note -* None. +* @note None. * ******************************************************************************/ void XHdcp1x_HandleTimeout(void *InstancePtr) @@ -774,141 +741,112 @@ void XHdcp1x_HandleTimeout(void *InstancePtr) XHdcp1x_TxHandleTimeout(&(HdcpPtr->Tx)); } #endif - - return; } /*****************************************************************************/ /** +* This function sets the debug printf function for the module. * -* This function sets the debug printf function for the module +* @param PrintfFunc is the printf function. * -* @param PrintfFunc the printf function +* @return None. * -* @return -* void -* -* @note -* None. +* @note None. * ******************************************************************************/ void XHdcp1x_SetDebugPrintf(XHdcp1x_Printf PrintfFunc) { XHdcp1xDebugPrintf = PrintfFunc; - return; } /*****************************************************************************/ /** +* This function sets the debug log message function for the module. * -* This function sets the debug log message function for the module +* @param LogFunc is the debug logging function. * -* @param LogFunc the debug logging function +* @return None. * -* @return -* void -* -* @note -* None. +* @note None. * ******************************************************************************/ void XHdcp1x_SetDebugLogMsg(XHdcp1x_LogMsg LogFunc) { XHdcp1xDebugLogMsg = LogFunc; - return; } /*****************************************************************************/ /** +* This function sets the KSV revocation list check function for the module. * -* This function sets the KSV revocation list check function for the module +* @param RevokeCheckFunc is the KSV revocation list check function. * -* @param RevokeCheckFunc the KSV revocation list check function +* @return None. * -* @return -* void -* -* @note -* None. +* @note None. * ******************************************************************************/ void XHdcp1x_SetKsvRevokeCheck(XHdcp1x_KsvRevokeCheck RevokeCheckFunc) { XHdcp1xKsvRevokeCheck = RevokeCheckFunc; - return; } /*****************************************************************************/ /** +* This function sets timer start function for the module. * -* This function sets timer start function for the module +* @param TimerStartFunc is the timer start function. * -* @param TimerStartFunc the timer start function +* @return None. * -* @return -* void -* -* @note -* None. +* @note None. * ******************************************************************************/ void XHdcp1x_SetTimerStart(XHdcp1x_TimerStart TimerStartFunc) { XHdcp1xTimerStart = TimerStartFunc; - return; } /*****************************************************************************/ /** +* This function sets timer stop function for the module. * -* This function sets timer stop function for the module +* @param TimerStopFunc is the timer stop function. * -* @param TimerStopFunc the timer stop function +* @return None. * -* @return -* void -* -* @note -* None. +* @note None. * ******************************************************************************/ void XHdcp1x_SetTimerStop(XHdcp1x_TimerStop TimerStopFunc) { XHdcp1xTimerStop = TimerStopFunc; - return; } /*****************************************************************************/ /** +* This function sets timer busy delay function for the module. * -* This function sets timer busy delay function for the module +* @param TimerDelayFunc is the timer busy delay function. * -* @param TimerDelayFunc the timer busy delay function +* @return None. * -* @return -* void -* -* @note -* None. +* @note None. * ******************************************************************************/ void XHdcp1x_SetTimerDelay(XHdcp1x_TimerDelay TimerDelayFunc) { XHdcp1xTimerDelay = TimerDelayFunc; - return; } /*****************************************************************************/ /** +* This function retrieves the version of the HDCP driver software. * -* This function retrieves the version of the hdcp driver software +* @return The software driver version. * -* @return -* The software driver version -* -* @note -* None. +* @note None. * ******************************************************************************/ u32 XHdcp1x_GetDriverVersion(void) @@ -918,16 +856,13 @@ u32 XHdcp1x_GetDriverVersion(void) /*****************************************************************************/ /** +* This function retrieves the cipher version of an HDCP interface. * -* This function retrieves the cipher version of an hdcp interface +* @param InstancePtr is the interface to query. * -* @param InstancePtr the interface to query +* @return The cipher version used by the interface * -* @return -* The cipher version used by the interface -* -* @note -* None. +* @note None. * ******************************************************************************/ u32 XHdcp1x_GetVersion(const XHdcp1x *InstancePtr) @@ -967,15 +902,13 @@ u32 XHdcp1x_GetVersion(const XHdcp1x *InstancePtr) /*****************************************************************************/ /** * -* This function performs a debug display of an hdcp instance +* This function performs a debug display of an HDCP instance. * -* @param InstancePtr the interface to display +* @param InstancePtr is the interface to display. * -* @return -* void +* @return None. * -* @note -* None. +* @note None. * ******************************************************************************/ void XHdcp1x_Info(const XHdcp1x *InstancePtr) @@ -1000,6 +933,4 @@ void XHdcp1x_Info(const XHdcp1x *InstancePtr) { XHDCP_DEBUG_PRINTF("unknown interface type\r\n"); } - - return; } diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x.h b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x.h index 09741548..9055f1e3 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x.h +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x.h @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,11 +42,11 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. -* 1.01 07/23/15 Additional documentation and formating +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ + #ifndef XHDCP1X_H /**< Prevent circular inclusions by using protection macros */ #define XHDCP1X_H @@ -56,6 +56,7 @@ extern "C" { #endif /***************************** Include Files *********************************/ + #include "xil_types.h" #include "xstatus.h" #include "xtmrctr.h" @@ -74,13 +75,13 @@ typedef void (*XHdcp1x_Callback)(void *CallbackRef); * This typedef defines the function interface that is to be used for debug * print statements within this driver */ -typedef void (*XHdcp1x_Printf)(const char* fmt, ...); +typedef void (*XHdcp1x_Printf)(const char *fmt, ...); /** * This typedef defines the function interface that is to be used for debug * log message statements within this driver */ -typedef void (*XHdcp1x_LogMsg)(const char* fmt, ...); +typedef void (*XHdcp1x_LogMsg)(const char *fmt, ...); /** * This typedef contains configuration information for the HDCP core. @@ -90,7 +91,8 @@ typedef struct { u32 BaseAddress; /**< The base address of the core */ u32 SysFrequency; /**< The main clock frequency of the core */ u16 IsRx; /**< Flag indicating the core direction */ - u16 IsHDMI; /**< Flag indicating the core type */ + u16 IsHDMI; /**< Flag indicating if the core is meant to + work with HDMI. */ } XHdcp1x_Config; /** @@ -116,8 +118,8 @@ typedef struct { } XHdcp1x_Cipher; /** -* This typedef defines the statistics collected by a port instance -*/ + * This typedef defines the statistics collected by a port instance + */ typedef struct { u32 IntCount; /**< The number of interrupts detected */ } XHdcp1x_PortStats; @@ -142,8 +144,8 @@ typedef struct XHdcp1x_PortStruct { } XHdcp1x_Port; /** -* This typedef defines the statistics collected transmit port instance -*/ + * This typedef defines the statistics collected transmit port instance + */ typedef struct { u32 AuthFailed; /**< Num of failed authentication attempts */ u32 AuthPassed; /**< Num of passed authentication attempts */ @@ -154,8 +156,8 @@ typedef struct { } XHdcp1x_TxStats; /** -* This typedef defines the statistics collected receive port instance -*/ + * This typedef defines the statistics collected receive port instance + */ typedef struct { u32 AuthAttempts; /**< Num of rxd authentication requests */ u32 LinkFailures; /**< Num of link verifications that failed */ @@ -163,10 +165,10 @@ typedef struct { } XHdcp1x_RxStats; /** -* This typedef defines the elements that are common to both RX and TX HDCP -* interfaces. The fields within this typedef must align with both the RX -* and TX definitions -*/ + * This typedef defines the elements that are common to both RX and TX HDCP + * interfaces. The fields within this typedef must align with both the RX + * and TX definitions + */ typedef struct { const XHdcp1x_Config *CfgPtr; /**< The cipher core config */ u32 IsReady; /**< The ready flag */ @@ -175,8 +177,8 @@ typedef struct { } XHdcp1x_Common; /** -* This typedef contains the transmit HDCP interface -*/ + * This typedef contains the transmit HDCP interface + */ typedef struct { const XHdcp1x_Config *CfgPtr; /**< The cipher core config */ u32 IsReady; /**< The ready flag */ @@ -192,8 +194,8 @@ typedef struct { } XHdcp1x_Tx; /** -* This typedef contains the receive HDCP interface -*/ + * This typedef contains the receive HDCP interface + */ typedef struct { const XHdcp1x_Config *CfgPtr; /**< The cipher core config */ u32 IsReady; /**< The ready flag */ @@ -207,8 +209,8 @@ typedef struct { } XHdcp1x_Rx; /** -* This typedef contains an instance of an HDCP interface -*/ + * This typedef contains an instance of an HDCP interface + */ typedef union { XHdcp1x_Common Common; /**< The common interface elements */ XHdcp1x_Tx Tx; /**< The transmit interface elements */ @@ -219,31 +221,31 @@ typedef union { * This typedef defines the function interface that is to be used for checking * a specific KSV against the platforms revocation list */ -typedef int (*XHdcp1x_KsvRevokeCheck)(const XHdcp1x *InstancePtr, u64 Ksv); +typedef int (*XHdcp1x_KsvRevokeCheck)(const XHdcp1x *InstancePtr, u64 Ksv); /** * This typedef defines the function interface that is to be used for starting * a one shot timer on behalf of an HDCP interface within the underlying * platform */ -typedef int (*XHdcp1x_TimerStart)(const XHdcp1x *InstancePtr, u16 TmoInMs); +typedef int (*XHdcp1x_TimerStart)(const XHdcp1x *InstancePtr, u16 TmoInMs); /** * This typedef defines the function interface that is to be used for stopping * a timer on behalf of an HDCP interface */ -typedef int (*XHdcp1x_TimerStop)(const XHdcp1x *InstancePtr); +typedef int (*XHdcp1x_TimerStop)(const XHdcp1x *InstancePtr); /** * This typedef defines the function interface that is to be used for * performing a busy delay on behalf of an HDCP interface */ -typedef int (*XHdcp1x_TimerDelay)(const XHdcp1x *InstancePtr, u16 DelayInMs); - +typedef int (*XHdcp1x_TimerDelay)(const XHdcp1x *InstancePtr, u16 DelayInMs); /***************** Macros (Inline Functions) Definitions *********************/ /************************** Function Prototypes ******************************/ + XHdcp1x_Config *XHdcp1x_LookupConfig(u16 DeviceId); int XHdcp1x_CfgInitialize(XHdcp1x *InstancePtr, const XHdcp1x_Config *CfgPtr, diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher.c index bbb375dd..e4dd15d6 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,13 +42,13 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. -* 1.01 07/23/15 Additional documentation and formating +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ /***************************** Include Files *********************************/ + #include #include #include "xhdcp1x.h" @@ -65,343 +65,176 @@ /*****************************************************************************/ /** +* This function performs register read from a cipher. * -* This function performs register read from a cipher +* @param InstancePtr is the instance to read from. +* @param Reg is the register to read. * -* @param InstancePtr the instance to read from -* @param Reg the register to read +* @return The current contents of the indicated register. * -* @return -* The current contents of the indicated register -* -* @note -* None. +* @note None. * ******************************************************************************/ -#define RegRead(InstancePtr, Reg) \ +#define RegRead(InstancePtr, Reg) \ XHdcp1x_CipherReadReg(InstancePtr->CfgPtr->BaseAddress, Reg) /*****************************************************************************/ /** +* This function performs register write to a cipher. * -* This function performs register write to a cipher +* @param InstancePtr is the instance to write to. +* @param Reg is the register to write. +* @param Value is the value to write. * -* @param InstancePtr the instance to write to -* @param Reg the register to write -* @param Value the value to write +* @return None. * -* @return -* void -* -* @note -* None. +* @note None. * ******************************************************************************/ -#define RegWrite(InstancePtr, Reg, Value) \ +#define RegWrite(InstancePtr, Reg, Value) \ XHdcp1x_CipherWriteReg(InstancePtr->CfgPtr->BaseAddress, Reg, Value) /*****************************************************************************/ /** +* This queries a cipher to determine if it is Display Port (DP). * -* This queries a cipher to determine if it is Display Port (DP) +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating DP (TRUE) or not (FALSE). * -* @return -* Truth value indicating DP (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ -#define IsDP(InstancePtr) \ +#define IsDP(InstancePtr) \ XHdcp1x_CipherIsDP(InstancePtr) /*****************************************************************************/ /** +* This queries a cipher to determine if it is HDMI. * -* This queries a cipher to determine if it is HDMI +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating HDMI (TRUE) or not (FALSE). * -* @return -* Truth value indicating HDMI (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ -#define IsHDMI(InstancePtr) \ +#define IsHDMI(InstancePtr) \ XHdcp1x_CipherIsHDMI(InstancePtr) /*****************************************************************************/ /** +* This queries a cipher to determine if it is a receiver. * -* This queries a cipher to determine if it is a receiver +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating receiver (TRUE) or not (FALSE). * -* @return -* Truth value indicating receiver (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ -#define IsRX(InstancePtr) \ +#define IsRX(InstancePtr) \ XHdcp1x_CipherIsRX(InstancePtr) /*****************************************************************************/ /** +* This queries a cipher to determine if it is a transmitter. * -* This queries a cipher to determine if it is a transmitter +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating transmitter (TRUE) or not (FALSE). * -* @return -* Truth value indicating transmitter (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ -#define IsTX(InstancePtr) \ +#define IsTX(InstancePtr) \ XHdcp1x_CipherIsTX(InstancePtr) /*****************************************************************************/ /** +* This queries a cipher to determine if it is enabled. * -* This queries a cipher to determine if it is enabled +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating transmitter (TRUE) or not (FALSE). * -* @return -* Truth value indicating transmitter (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ -#define IsEnabled(InstancePtr) \ +#define IsEnabled(InstancePtr) \ ((RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL) & \ XHDCP1X_CIPHER_BITMASK_CONTROL_ENABLE) != 0) /*****************************************************************************/ /** -* * This queries a cipher to determine if the XOR (encryption) function is -* currently in progress +* currently in progress. * -* @param InstancePtr the instance to query +* @param InstancePtr is the instance to query. * -* @return -* Truth value indicating in progress (TRUE) or not (FALSE) +* @return Truth value indicating in progress (TRUE) or not (FALSE). * -* @note -* None. +* @note None. * ******************************************************************************/ -#define XorInProgress(InstancePtr) \ +#define XorInProgress(InstancePtr) \ ((RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CIPHER_STATUS) & \ XHDCP1X_CIPHER_BITMASK_CIPHER_STATUS_XOR_IN_PROG) != 0) /*****************************************************************************/ /** +* This queries a cipher to determine if the local KSV is ready to read. * -* This queries a cipher to determine if the local KSV is ready to read +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating ready (TRUE) or not (FALSE). * -* @return -* Truth value indicating ready (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ -#define LocalKsvReady(InstancePtr) \ +#define LocalKsvReady(InstancePtr) \ ((RegRead(InstancePtr, XHDCP1X_CIPHER_REG_KEYMGMT_STATUS) & \ XHDCP1X_CIPHER_BITMASK_KEYMGMT_STATUS_KSV_READY) != 0) /*****************************************************************************/ /** +* This queries a cipher to determine if the Km value is ready. * -* This queries a cipher to determine if the Km value is ready +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating ready (TRUE) or not (FALSE). * -* @return -* Truth value indicating ready (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ -#define KmReady(InstancePtr) \ +#define KmReady(InstancePtr) \ ((RegRead(InstancePtr, XHDCP1X_CIPHER_REG_KEYMGMT_STATUS) & \ XHDCP1X_CIPHER_BITMASK_KEYMGMT_STATUS_Km_READY) != 0) +/*************************** Function Prototypes *****************************/ + +static void Enable(XHdcp1x_Cipher *InstancePtr); +static void Disable(XHdcp1x_Cipher *InstancePtr); +static void Init(XHdcp1x_Cipher *InstancePtr); + /************************** Function Definitions *****************************/ /*****************************************************************************/ /** +* This function initializes a cipher device. * -* This function enables a hdcp cipher -* -* @param InstancePtr the device to enable +* @param InstancePtr is the device to initialize. +* @param CfgPtr is the device configuration. * * @return -* void +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ -static void Enable(XHdcp1x_Cipher* InstancePtr) -{ - u32 Value = 0; - - /* Clear the register update bit */ - Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); - Value &= ~XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE; - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); - - /* Ensure that all encryption is disabled for now */ - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_ENCRYPT_ENABLE_H, 0x00ul); - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_ENCRYPT_ENABLE_L, 0x00ul); - - /* Ensure that XOR is disabled on tx and enabled for rx to start */ - Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CIPHER_CONTROL); - Value &= ~XHDCP1X_CIPHER_BITMASK_CIPHER_CONTROL_XOR_ENABLE; - if (IsRX(InstancePtr)) { - Value |= XHDCP1X_CIPHER_BITMASK_CIPHER_CONTROL_XOR_ENABLE; - } - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CIPHER_CONTROL, Value); - - /* Enable it */ - Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); - Value |= XHDCP1X_CIPHER_BITMASK_CONTROL_ENABLE; - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); - - /* Ensure that the register update bit is set */ - Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); - Value |= XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE; - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); - - return; -} - -/*****************************************************************************/ -/** -* -* This function disables a hdcp cipher -* -* @param InstancePtr the device to disable -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void Disable(XHdcp1x_Cipher* InstancePtr) -{ - u32 Value = 0; - - /* Ensure all interrupts are disabled */ - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_INTERRUPT_MASK, 0xFFFFFFFFul); - - /* Enable bypass operation */ - Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); - Value &= ~XHDCP1X_CIPHER_BITMASK_CONTROL_ENABLE; - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); - - /* Ensure that all encryption is disabled for now */ - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_ENCRYPT_ENABLE_H, 0x00ul); - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_ENCRYPT_ENABLE_L, 0x00ul); - - /* Ensure that XOR is disabled */ - Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CIPHER_CONTROL); - Value &= ~XHDCP1X_CIPHER_BITMASK_CIPHER_CONTROL_XOR_ENABLE; - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CIPHER_CONTROL, Value); - - /* Ensure that the register update bit is set */ - Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); - Value |= XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE; - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); - - /* Wait until the XOR has actually stopped */ - while (XorInProgress(InstancePtr)); - - return; -} - -/*****************************************************************************/ -/** -* -* This function initializes a hdcp cipher -* -* @param InstancePtr the device to initialize -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void Init(XHdcp1x_Cipher* InstancePtr) -{ - u32 Value = 0; - - /* Reset it */ - Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); - Value |= XHDCP1X_CIPHER_BITMASK_CONTROL_RESET; - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); - Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); - Value &= ~XHDCP1X_CIPHER_BITMASK_CONTROL_RESET; - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); - - /* Ensure all interrupts are disabled and cleared */ - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_INTERRUPT_MASK, (u32) (-1)); - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_INTERRUPT_STATUS, (u32) (-1)); - - /* Check for DP */ - if (IsDP(InstancePtr)) { - - /* Configure for four lanes SST */ - Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); - Value &= ~XHDCP1X_CIPHER_BITMASK_CONTROL_NUM_LANES; - Value |= (4u << 4); - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); - } - - /* Ensure that the register update bit is set */ - Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); - Value |= XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE; - RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); - - return; -} - -/*****************************************************************************/ -/** -* -* This function initializes a cipher device -* -* @param InstancePtr the device to initialize -* @param CfgPtr the device configuration -* -* @return -* XST_SUCCESS if successful. -* -* @note -* None. -* -******************************************************************************/ -int XHdcp1x_CipherCfgInitialize(XHdcp1x_Cipher* InstancePtr, - const XHdcp1x_Config* CfgPtr) +int XHdcp1x_CipherCfgInitialize(XHdcp1x_Cipher *InstancePtr, + const XHdcp1x_Config *CfgPtr) { int Status = XST_SUCCESS; @@ -445,51 +278,47 @@ int XHdcp1x_CipherCfgInitialize(XHdcp1x_Cipher* InstancePtr, /*****************************************************************************/ /** +* This function queries the link state of a cipher device. * -* This function queries the link state of a cipher device +* @param InstancePtr is the device to query. * -* @param InstancePtr the device to query +* @return Truth value. * -* @return -* Truth value -* -* @note -* None. +* @note None. * ******************************************************************************/ -int XHdcp1x_CipherIsLinkUp(const XHdcp1x_Cipher* InstancePtr) +int XHdcp1x_CipherIsLinkUp(const XHdcp1x_Cipher *InstancePtr) { - int isUp = FALSE; + int IsUp = FALSE; /* Verify arguments. */ Xil_AssertNonvoid(InstancePtr != NULL); /* Check for currently enabled */ if (IsEnabled(InstancePtr)) { - u32 Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_STATUS); - if ((Value & XHDCP1X_CIPHER_BITMASK_INTERRUPT_LINK_FAIL) != 0) - isUp = TRUE; + if ((Value & XHDCP1X_CIPHER_BITMASK_INTERRUPT_LINK_FAIL) != 0) { + IsUp = TRUE; + } } - return (isUp); + return (IsUp); } /*****************************************************************************/ /** +* This function enables a HDCP cipher. * -* This function enables a hdcp cipher -* -* @param InstancePtr the device to enable +* @param InstancePtr is the device to enable. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ -int XHdcp1x_CipherEnable(XHdcp1x_Cipher* InstancePtr) +int XHdcp1x_CipherEnable(XHdcp1x_Cipher *InstancePtr) { int Status = XST_SUCCESS; @@ -510,18 +339,17 @@ int XHdcp1x_CipherEnable(XHdcp1x_Cipher* InstancePtr) /*****************************************************************************/ /** * -* This function disables a hdcp cipher +* This function disables a HDCP cipher. * -* @param InstancePtr the device to disable +* @param InstancePtr is the device to disable. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ -int XHdcp1x_CipherDisable(XHdcp1x_Cipher* InstancePtr) +int XHdcp1x_CipherDisable(XHdcp1x_Cipher *InstancePtr) { int Status = XST_SUCCESS; @@ -533,26 +361,23 @@ int XHdcp1x_CipherDisable(XHdcp1x_Cipher* InstancePtr) Disable(InstancePtr); } - /* Return */ return (Status); } /*****************************************************************************/ /** +* This function configures the key selection value. * -* This function configures the key selection value -* -* @param InstancePtr the device to configure -* @param KeySelect the desired key select value +* @param InstancePtr is the device to configure. +* @param KeySelect is the desired key select value. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ -int XHdcp1x_CipherSetKeySelect(XHdcp1x_Cipher* InstancePtr, u8 KeySelect) +int XHdcp1x_CipherSetKeySelect(XHdcp1x_Cipher *InstancePtr, u8 KeySelect) { int Status = XST_SUCCESS; u32 Value = 0; @@ -572,20 +397,20 @@ int XHdcp1x_CipherSetKeySelect(XHdcp1x_Cipher* InstancePtr, u8 KeySelect) /*****************************************************************************/ /** +* This function initiates a request within the HDCP cipher. * -* This function initiates a request within the hdcp cipher -* -* @param InstancePtr the device to submit the request to -* @param Request the request to submit +* @param InstancePtr is the device to submit the request to. +* @param Request is the request to submit. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_NOT_ENABLE if the core is disabled. +* - XST_DEVICE_BUSY if the core is busy. * -* @note -* None. +* @note None. * ******************************************************************************/ -int XHdcp1x_CipherDoRequest(XHdcp1x_Cipher* InstancePtr, +int XHdcp1x_CipherDoRequest(XHdcp1x_Cipher *InstancePtr, XHdcp1x_CipherRequestType Request) { u32 Value = 0; @@ -593,7 +418,6 @@ int XHdcp1x_CipherDoRequest(XHdcp1x_Cipher* InstancePtr, /* Verify arguments. */ Xil_AssertNonvoid(InstancePtr != NULL); Xil_AssertNonvoid(Request >= (XHDCP1X_CIPHER_REQUEST_BLOCK)); -// Xil_AssertNonvoid(Request < (XHDCP1X_CIPHER_REQUEST_MAX)); /* Check that it is not disabled */ if (!IsEnabled(InstancePtr)) { @@ -617,7 +441,7 @@ int XHdcp1x_CipherDoRequest(XHdcp1x_Cipher* InstancePtr, /* Set the appropriate request bit and ensure that Km is always used */ Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CIPHER_CONTROL); Value &= ~XHDCP1X_CIPHER_BITMASK_CIPHER_CONTROL_REQUEST; - Value |= (XHDCP1X_CIPHER_VALUE_CIPHER_CONTROL_REQUEST_BLOCK<>= 4; } - /* Return */ return (NumLanes); } /*****************************************************************************/ /** +* This function configures the number of lanes of the HDCP cipher. * -* This function configures the number of lanes of the hdcp cipher -* -* @param InstancePtr the device to configure -* @param NumLanes the number of lanes to configure +* @param InstancePtr is the device to configure. +* @param NumLanes is the number of lanes to configure. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ -int XHdcp1x_CipherSetNumLanes(XHdcp1x_Cipher* InstancePtr, u32 NumLanes) +int XHdcp1x_CipherSetNumLanes(XHdcp1x_Cipher *InstancePtr, u32 NumLanes) { int Status = XST_SUCCESS; u32 Value = 0; @@ -724,7 +537,6 @@ int XHdcp1x_CipherSetNumLanes(XHdcp1x_Cipher* InstancePtr, u32 NumLanes) /* Check for HDMI */ if (IsHDMI(InstancePtr)) { - /* Verify NumLanes (again) */ Xil_AssertNonvoid(NumLanes == 1); @@ -733,11 +545,9 @@ int XHdcp1x_CipherSetNumLanes(XHdcp1x_Cipher* InstancePtr, u32 NumLanes) Value &= ~XHDCP1X_CIPHER_BITMASK_CONTROL_NUM_LANES; Value |= (NumLanes << 4); RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); - } /* Otherwise - must be DP */ else { - /* Verify NumLanes (again) */ Xil_AssertNonvoid(NumLanes != 3); @@ -753,22 +563,19 @@ int XHdcp1x_CipherSetNumLanes(XHdcp1x_Cipher* InstancePtr, u32 NumLanes) /*****************************************************************************/ /** +* This function retrieves the current encryption stream map. * -* This function retrieves the current encryption stream map +* @param InstancePtr is the device to query. * -* @param InstancePtr the device to query +* @return The current encryption stream map. * -* @return -* The current encryption stream map. -* -* @note -* In the case of the receiver version of this core, the XOR in progress bit -* needs to be checked as well as the encryption map to fully determine if -* encryption is enabled for the SST case. This is reason for the additional -* check in this code +* @note In the case of the receiver version of this core, the XOR in +* progress bit needs to be checked as well as the encryption map +* to fully determine if encryption is enabled for the SST case. +* This is the reason for the additional check in this code. * ******************************************************************************/ -u64 XHdcp1x_CipherGetEncryption(const XHdcp1x_Cipher* InstancePtr) +u64 XHdcp1x_CipherGetEncryption(const XHdcp1x_Cipher *InstancePtr) { u64 StreamMap = 0; @@ -795,20 +602,20 @@ u64 XHdcp1x_CipherGetEncryption(const XHdcp1x_Cipher* InstancePtr) /*****************************************************************************/ /** +* This function enables encryption on a set of streams. * -* This function enables encryption on a set of streams -* -* @param InstancePtr the device to configure -* @param StreamMap the bit map of streams to enable encryption on +* @param InstancePtr is the device to configure. +* @param StreamMap is the bit map of streams to enable encryption on. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_NOT_ENABLE if the core is not enabled. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ -int XHdcp1x_CipherEnableEncryption(XHdcp1x_Cipher* InstancePtr, u64 StreamMap) +int XHdcp1x_CipherEnableEncryption(XHdcp1x_Cipher *InstancePtr, u64 StreamMap) { u32 Value = 0; @@ -864,19 +671,20 @@ int XHdcp1x_CipherEnableEncryption(XHdcp1x_Cipher* InstancePtr, u64 StreamMap) /*****************************************************************************/ /** * -* This function disables encryption on a set of streams +* This function disables encryption on a set of streams. * -* @param InstancePtr the device to configure -* @param StreamMap the bit map of streams to disable encryption on +* @param InstancePtr is the device to configure. +* @param StreamMap is the bit map of streams to disable encryption on. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_NOT_ENABLE if the core is not enabled. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ -int XHdcp1x_CipherDisableEncryption(XHdcp1x_Cipher* InstancePtr, u64 StreamMap) +int XHdcp1x_CipherDisableEncryption(XHdcp1x_Cipher *InstancePtr, u64 StreamMap) { u32 Val = 0; int DisableXor = TRUE; @@ -947,19 +755,16 @@ int XHdcp1x_CipherDisableEncryption(XHdcp1x_Cipher* InstancePtr, u64 StreamMap) /*****************************************************************************/ /** +* This function reads the local KSV value from the cipher. * -* This function reads the local KSV value from the cipher +* @param InstancePtr is the device to query. * -* @param InstancePtr the device to query +* @return The local KSV value. * - * @return -* The local KSV value -* -* @note -* None. +* @note None. * ******************************************************************************/ -u64 XHdcp1x_CipherGetLocalKsv(const XHdcp1x_Cipher* InstancePtr) +u64 XHdcp1x_CipherGetLocalKsv(const XHdcp1x_Cipher *InstancePtr) { u32 Val = 0; u32 Guard = 0x400ul; @@ -977,7 +782,6 @@ u64 XHdcp1x_CipherGetLocalKsv(const XHdcp1x_Cipher* InstancePtr) Val = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_KEYMGMT_STATUS); Val &= XHDCP1X_CIPHER_BITMASK_KEYMGMT_STATUS_KSV_READY; if (Val == 0) { - /* Abort any running Km calculation just in case */ Val = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_KEYMGMT_CONTROL); Val |= XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_ABORT_Km; @@ -998,7 +802,6 @@ u64 XHdcp1x_CipherGetLocalKsv(const XHdcp1x_Cipher* InstancePtr) /* Confirm no timeout */ if (Guard != 0) { - /* Update Ksv */ Ksv = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_KSV_LOCAL_H); Ksv &= 0xFFul; @@ -1011,21 +814,17 @@ u64 XHdcp1x_CipherGetLocalKsv(const XHdcp1x_Cipher* InstancePtr) /*****************************************************************************/ /** +* This function reads the remote KSV value from the cipher. * -* This function reads the remote KSV value from the cipher +* @param InstancePtr is the device to query. * -* @param InstancePtr the device to query +* @return The remote KSV value. * -* @return -* The remote KSV value -* -* @note -* None. +* @note None. * ******************************************************************************/ -u64 XHdcp1x_CipherGetRemoteKsv(const XHdcp1x_Cipher* InstancePtr) +u64 XHdcp1x_CipherGetRemoteKsv(const XHdcp1x_Cipher *InstancePtr) { - /* Locals */ u64 Ksv = 0; /* Verify arguments. */ @@ -1036,27 +835,26 @@ u64 XHdcp1x_CipherGetRemoteKsv(const XHdcp1x_Cipher* InstancePtr) Ksv <<= 32; Ksv |= RegRead(InstancePtr, XHDCP1X_CIPHER_REG_KSV_REMOTE_L); - /* Return */ return (Ksv); } /*****************************************************************************/ /** +* This function writes the remote KSV value to the cipher. * -* This function writes the remote KSV value to the cipher -* -* @param InstancePtr the device to write to -* @param Ksv the remote KSV value to write +* @param InstancePtr is the device to write to. +* @param Ksv is the remote KSV value to write. * * @return -* XST_SUCCESS if successful. +* - 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. +* @note Whenever this function is called, the underlying driver will +* initiate the calculation of the Km value and wait for it to +* complete. * ******************************************************************************/ -int XHdcp1x_CipherSetRemoteKsv(XHdcp1x_Cipher* InstancePtr, u64 Ksv) +int XHdcp1x_CipherSetRemoteKsv(XHdcp1x_Cipher *InstancePtr, u64 Ksv) { u32 Value = 0; u32 Guard = 0x400ul; @@ -1111,26 +909,24 @@ int XHdcp1x_CipherSetRemoteKsv(XHdcp1x_Cipher* InstancePtr, u64 Ksv) } /*****************************************************************************/ - /** +* This function reads the contents of the B register in BM0. * -* This function reads the contents of the B register in BM0 -* -* @param InstancePtr the device to query -* @param X to be loaded with the contents of Bx -* @param Y to be loaded with the contents of By -* @param Z to be loaded with the contents of Bz +* @param InstancePtr is the device to query. +* @param X is to be loaded with the contents of Bx. +* @param Y is to be loaded with the contents of By. +* @param Z is to be loaded with the contents of Bz. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_NOT_ENABLED otherwise. * -* @note -* A NULL pointer can be passed in any of X, Y and Z. If so, then -* this portion of the B register is not returned to the caller. +* @note A NULL pointer can be passed in any of X, Y and Z. If so, then +* this portion of the B register is not returned to the caller. * ******************************************************************************/ -int XHdcp1x_CipherGetB(const XHdcp1x_Cipher* InstancePtr, u32* X, u32* Y, - u32* Z) +int XHdcp1x_CipherGetB(const XHdcp1x_Cipher *InstancePtr, u32 *X, u32 *Y, + u32 *Z) { /* Verify arguments. */ Xil_AssertNonvoid(InstancePtr != NULL); @@ -1163,22 +959,21 @@ int XHdcp1x_CipherGetB(const XHdcp1x_Cipher* InstancePtr, u32* X, u32* Y, /*****************************************************************************/ /** +* This function writes the contents of the B register in BM0. * -* This function writes the contents of the B register in BM0 -* -* @param InstancePtr the device to write to -* @param X the value to be written to Bx -* @param Y the value to be written to By -* @param Z the value to be written to Bz +* @param InstancePtr is the device to write to. +* @param X is the value to be written to Bx. +* @param Y is the value to be written to By. +* @param Z is the value to be written to Bz. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_NOT_ENABLED otherwise. * -* @note -* None +* @note None. * ******************************************************************************/ -int XHdcp1x_CipherSetB(XHdcp1x_Cipher* InstancePtr, u32 X, u32 Y, u32 Z) +int XHdcp1x_CipherSetB(XHdcp1x_Cipher *InstancePtr, u32 X, u32 Y, u32 Z) { u32 Value = 0; @@ -1217,24 +1012,23 @@ int XHdcp1x_CipherSetB(XHdcp1x_Cipher* InstancePtr, u32 X, u32 Y, u32 Z) /*****************************************************************************/ /** +* This function reads the contents of the K register in BM0. * -* This function reads the contents of the K register in BM0 -* -* @param InstancePtr the device to query -* @param X to be loaded with the contents of Kx -* @param Y to be loaded with the contents of Ky -* @param Z to be loaded with the contents of Kz +* @param InstancePtr is the device to query. +* @param X is to be loaded with the contents of Kx. +* @param Y is to be loaded with the contents of Ky. +* @param Z is to be loaded with the contents of Kz. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_NOT_ENABLED otherwise. * -* @note -* A NULL pointer can be passed in any of X, Y and Z. If so, then -* this portion of the K register is not returned to the caller. +* @note A NULL pointer can be passed in any of X, Y and Z. If so, then +* this portion of the K register is not returned to the caller. * ******************************************************************************/ -int XHdcp1x_CipherGetK(const XHdcp1x_Cipher* InstancePtr, u32* X, u32* Y, - u32* Z) +int XHdcp1x_CipherGetK(const XHdcp1x_Cipher *InstancePtr, u32 *X, u32 *Y, + u32 *Z) { /* Verify arguments. */ Xil_AssertNonvoid(InstancePtr != NULL); @@ -1267,22 +1061,21 @@ int XHdcp1x_CipherGetK(const XHdcp1x_Cipher* InstancePtr, u32* X, u32* Y, /*****************************************************************************/ /** +* This function writes the contents of the K register in BM0. * -* This function writes the contents of the K register in BM0 -* -* @param InstancePtr the device to write to -* @param X the value to be written to Kx -* @param Y the value to be written to Ky -* @param Z the value to be written to Kz +* @param InstancePtr is the device to write to. +* @param X is the value to be written to Kx. +* @param Y is the value to be written to Ky. +* @param Z is the value to be written to Kz. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_NOT_ENABLED otherwise. * -* @note -* None +* @note None. * ******************************************************************************/ -int XHdcp1x_CipherSetK(XHdcp1x_Cipher* InstancePtr, u32 X, u32 Y, u32 Z) +int XHdcp1x_CipherSetK(XHdcp1x_Cipher *InstancePtr, u32 X, u32 Y, u32 Z) { u32 Value = 0; @@ -1321,19 +1114,16 @@ int XHdcp1x_CipherSetK(XHdcp1x_Cipher* InstancePtr, u32 X, u32 Y, u32 Z) /*****************************************************************************/ /** +* This function reads the contents of the Mi/An register of BM0. * -* This function reads the contents of the Mi/An register of BM0 +* @param InstancePtr is the device to query. * -* @param InstancePtr the device to query +* @return The contents of the register. * -* @return -* The contents of the register -* -* @note -* None +* @note None. * ******************************************************************************/ -u64 XHdcp1x_CipherGetMi(const XHdcp1x_Cipher* InstancePtr) +u64 XHdcp1x_CipherGetMi(const XHdcp1x_Cipher *InstancePtr) { u64 Mi = 0; @@ -1355,19 +1145,16 @@ u64 XHdcp1x_CipherGetMi(const XHdcp1x_Cipher* InstancePtr) /*****************************************************************************/ /** +* This function reads the contents of the Ri register of BM0. * -* This function reads the contents of the Ri register of BM0 +* @param InstancePtr is the device to query. * -* @param InstancePtr the device to query +* @return The contents of the register. * -* @return -* The contents of the register -* -* @note -* None +* @note None. * ******************************************************************************/ -u16 XHdcp1x_CipherGetRi(const XHdcp1x_Cipher* InstancePtr) +u16 XHdcp1x_CipherGetRi(const XHdcp1x_Cipher *InstancePtr) { u16 Ri = 0; @@ -1379,7 +1166,7 @@ u16 XHdcp1x_CipherGetRi(const XHdcp1x_Cipher* InstancePtr) return (XST_NOT_ENABLED); } - /* Determine theRi */ + /* Determine Ri */ Ri = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CIPHER_Ri); return (Ri); @@ -1388,18 +1175,16 @@ u16 XHdcp1x_CipherGetRi(const XHdcp1x_Cipher* InstancePtr) /*****************************************************************************/ /** * -* This function reads the contents of the Mo register of the device +* This function reads the contents of the Mo register of the device. * -* @param InstancePtr the device to query +* @param InstancePtr is the device to query. * -* @return -* The contents of the Mo register +* @return The contents of the Mo register. * -* @note -* None +* @note None. * ******************************************************************************/ -u64 XHdcp1x_CipherGetMo(const XHdcp1x_Cipher* InstancePtr) +u64 XHdcp1x_CipherGetMo(const XHdcp1x_Cipher *InstancePtr) { u64 Mo = 0; @@ -1422,18 +1207,16 @@ u64 XHdcp1x_CipherGetMo(const XHdcp1x_Cipher* InstancePtr) /*****************************************************************************/ /** * -* This function reads the contents of the Ro register of the device +* This function reads the contents of the Ro register of the device. * -* @param InstancePtr the device to query +* @param InstancePtr is the device to query. * -* @return -* The contents of the Ro register +* @return The contents of the Ro register. * -* @note -* None +* @note None. * ******************************************************************************/ -u16 XHdcp1x_CipherGetRo(const XHdcp1x_Cipher* InstancePtr) +u16 XHdcp1x_CipherGetRo(const XHdcp1x_Cipher *InstancePtr) { u16 Ro = 0; @@ -1453,19 +1236,16 @@ u16 XHdcp1x_CipherGetRo(const XHdcp1x_Cipher* InstancePtr) /*****************************************************************************/ /** +* This function reads the version of the HDCP cipher core. * -* This function reads the version of the hdcp cipher core +* @param InstancePtr is the device to query. * -* @param InstancePtr the device to query +* @return The version of the HDCP cipher device. * -* @return -* The version of the hdcp cipher device -* -* @note -* None +* @note None. * ******************************************************************************/ -u32 XHdcp1x_CipherGetVersion(const XHdcp1x_Cipher* InstancePtr) +u32 XHdcp1x_CipherGetVersion(const XHdcp1x_Cipher *InstancePtr) { u32 Version = 0; @@ -1477,3 +1257,129 @@ u32 XHdcp1x_CipherGetVersion(const XHdcp1x_Cipher* InstancePtr) return (Version); } + +/*****************************************************************************/ +/** +* This function enables an HDCP cipher. +* +* @param InstancePtr is the device to enable. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void Enable(XHdcp1x_Cipher *InstancePtr) +{ + u32 Value = 0; + + /* Clear the register update bit */ + Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); + Value &= ~XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE; + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); + + /* Ensure that all encryption is disabled for now */ + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_ENCRYPT_ENABLE_H, 0x00ul); + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_ENCRYPT_ENABLE_L, 0x00ul); + + /* Ensure that XOR is disabled on tx and enabled for rx to start */ + Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CIPHER_CONTROL); + Value &= ~XHDCP1X_CIPHER_BITMASK_CIPHER_CONTROL_XOR_ENABLE; + if (IsRX(InstancePtr)) { + Value |= XHDCP1X_CIPHER_BITMASK_CIPHER_CONTROL_XOR_ENABLE; + } + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CIPHER_CONTROL, Value); + + /* Enable it */ + Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); + Value |= XHDCP1X_CIPHER_BITMASK_CONTROL_ENABLE; + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); + + /* Ensure that the register update bit is set */ + Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); + Value |= XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE; + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); +} + +/*****************************************************************************/ +/** +* This function disables a HDCP cipher. +* +* @param InstancePtr is the device to disable. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void Disable(XHdcp1x_Cipher *InstancePtr) +{ + u32 Value = 0; + + /* Ensure all interrupts are disabled */ + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_INTERRUPT_MASK, 0xFFFFFFFFul); + + /* Enable bypass operation */ + Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); + Value &= ~XHDCP1X_CIPHER_BITMASK_CONTROL_ENABLE; + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); + + /* Ensure that all encryption is disabled for now */ + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_ENCRYPT_ENABLE_H, 0x00ul); + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_ENCRYPT_ENABLE_L, 0x00ul); + + /* Ensure that XOR is disabled */ + Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CIPHER_CONTROL); + Value &= ~XHDCP1X_CIPHER_BITMASK_CIPHER_CONTROL_XOR_ENABLE; + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CIPHER_CONTROL, Value); + + /* Ensure that the register update bit is set */ + Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); + Value |= XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE; + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); + + /* Wait until the XOR has actually stopped */ + while (XorInProgress(InstancePtr)); +} + +/*****************************************************************************/ +/** +* This function initializes an HDCP cipher. +* +* @param InstancePtr is the device to initialize. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void Init(XHdcp1x_Cipher *InstancePtr) +{ + u32 Value = 0; + + /* Reset it */ + Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); + Value |= XHDCP1X_CIPHER_BITMASK_CONTROL_RESET; + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); + Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); + Value &= ~XHDCP1X_CIPHER_BITMASK_CONTROL_RESET; + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); + + /* Ensure all interrupts are disabled and cleared */ + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_INTERRUPT_MASK, (u32) (-1)); + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_INTERRUPT_STATUS, (u32) (-1)); + + /* Check for DP */ + if (IsDP(InstancePtr)) { + /* Configure for four lanes SST */ + Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); + Value &= ~XHDCP1X_CIPHER_BITMASK_CONTROL_NUM_LANES; + Value |= (4u << 4); + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); + } + + /* Ensure that the register update bit is set */ + Value = RegRead(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL); + Value |= XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE; + RegWrite(InstancePtr, XHDCP1X_CIPHER_REG_CONTROL, Value); +} diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher.h b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher.h index e5fd4904..fcdf6ec3 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher.h +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher.h @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -41,10 +41,11 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ + #ifndef XHDCP1X_CIPHER_H /**< Prevent circular inclusions by using protection macros */ #define XHDCP1X_CIPHER_H @@ -54,6 +55,7 @@ extern "C" { #endif /***************************** Include Files *********************************/ + #include "xhdcp1x.h" #include "xhdcp1x_cipher_hw.h" #include "xstatus.h" @@ -191,11 +193,11 @@ u64 XHdcp1x_CipherGetLocalKsv(const XHdcp1x_Cipher *InstancePtr); u64 XHdcp1x_CipherGetRemoteKsv(const XHdcp1x_Cipher *InstancePtr); int XHdcp1x_CipherSetRemoteKsv(XHdcp1x_Cipher *InstancePtr, u64 Ksv); -int XHdcp1x_CipherGetB(const XHdcp1x_Cipher *InstancePtr, u32* X, u32* Y, - u32* Z); +int XHdcp1x_CipherGetB(const XHdcp1x_Cipher *InstancePtr, u32 *X, u32 *Y, + u32 *Z); int XHdcp1x_CipherSetB(XHdcp1x_Cipher *InstancePtr, u32 X, u32 Y, u32 Z); -int XHdcp1x_CipherGetK(const XHdcp1x_Cipher *InstancePtr, u32* X, u32* Y, - u32* Z); +int XHdcp1x_CipherGetK(const XHdcp1x_Cipher *InstancePtr, u32 *X, u32 *Y, + u32 *Z); int XHdcp1x_CipherSetK(XHdcp1x_Cipher *InstancePtr, u32 X, u32 Y, u32 Z); u64 XHdcp1x_CipherGetMi(const XHdcp1x_Cipher *InstancePtr); @@ -207,10 +209,8 @@ u32 XHdcp1x_CipherGetVersion(const XHdcp1x_Cipher *InstancePtr); void XHdcp1x_CipherHandlerInterrupt(void *InstancePtr); - #ifdef __cplusplus } #endif - #endif /* XHDCP1X_CIPHER_H */ diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher_hw.h b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher_hw.h index b146a764..e6c8739c 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher_hw.h +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher_hw.h @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -46,11 +46,11 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. -* 1.01 07/23/15 Fixed RNG cipher request value +* 1.00 fidus 07/16/15 Initial release. * * - ******************************************************************************/ +******************************************************************************/ + #ifndef XHDCP1X_CIPHER_HW_H /**< Prevent circular inclusions by using protection macros */ #define XHDCP1X_CIPHER_HW_H @@ -65,76 +65,169 @@ extern "C" { /************************** Constant Definitions *****************************/ // HDCP Cipher register offsets -#define XHDCP1X_CIPHER_REG_VERSION (0x0000u) /**< Version register offset */ -#define XHDCP1X_CIPHER_REG_TYPE (0x0004u) /**< Type register offset */ -#define XHDCP1X_CIPHER_REG_SCRATCH (0x0008u) /**< Scratch pad register offset */ -#define XHDCP1X_CIPHER_REG_CONTROL (0x000Cu) /**< Control register offset */ -#define XHDCP1X_CIPHER_REG_STATUS (0x0010u) /**< Status register offset */ -#define XHDCP1X_CIPHER_REG_INTERRUPT_MASK (0x0014u) /**< Interrupt Mask register offset */ -#define XHDCP1X_CIPHER_REG_INTERRUPT_STATUS (0x0018u) /**< Interrupt Status register offset */ -#define XHDCP1X_CIPHER_REG_ENCRYPT_ENABLE_H (0x0020u) /**< Encryption Enable (High) register offset */ -#define XHDCP1X_CIPHER_REG_ENCRYPT_ENABLE_L (0x0024u) /**< Encryption Enable (Low) register offset */ +#define XHDCP1X_CIPHER_REG_VERSION (0x0000u) /**< Version register + offset */ +#define XHDCP1X_CIPHER_REG_TYPE (0x0004u) /**< Type register offset */ +#define XHDCP1X_CIPHER_REG_SCRATCH (0x0008u) /**< Scratch pad register + offset */ +#define XHDCP1X_CIPHER_REG_CONTROL (0x000Cu) /**< Control register + offset */ +#define XHDCP1X_CIPHER_REG_STATUS (0x0010u) /**< Status register + offset */ +#define XHDCP1X_CIPHER_REG_INTERRUPT_MASK (0x0014u) /**< Interrupt Mask + register offset */ +#define XHDCP1X_CIPHER_REG_INTERRUPT_STATUS \ + (0x0018u) /**< Interrupt Status + register offset */ +#define XHDCP1X_CIPHER_REG_ENCRYPT_ENABLE_H \ + (0x0020u) /**< Encryption Enable (High) + register offset */ +#define XHDCP1X_CIPHER_REG_ENCRYPT_ENABLE_L \ + (0x0024u) /**< Encryption Enable (Low) + register offset */ -#define XHDCP1X_CIPHER_REG_KEYMGMT_CONTROL (0x002Cu) /**< Key Management Control register offset */ -#define XHDCP1X_CIPHER_REG_KEYMGMT_STATUS (0x0030u) /**< Key Management Status register offset */ -#define XHDCP1X_CIPHER_REG_KSV_LOCAL_H (0x0038u) /**< Local KSV (High) register offset */ -#define XHDCP1X_CIPHER_REG_KSV_LOCAL_L (0x003Cu) /**< Local KSV (Low) register offset */ -#define XHDCP1X_CIPHER_REG_KSV_REMOTE_H (0x0040u) /**< Remote KSV (High) offset */ -#define XHDCP1X_CIPHER_REG_KSV_REMOTE_L (0x0044u) /**< Remote KSV (Low) register offset */ -#define XHDCP1X_CIPHER_REG_Km_H (0x0048u) /**< Km (High) register offset */ -#define XHDCP1X_CIPHER_REG_Km_L (0x004Cu) /**< Km (Low) register offset */ +#define XHDCP1X_CIPHER_REG_KEYMGMT_CONTROL \ + (0x002Cu) /**< Key Management Control + register offset */ +#define XHDCP1X_CIPHER_REG_KEYMGMT_STATUS (0x0030u) /**< Key Management Status + register offset */ +#define XHDCP1X_CIPHER_REG_KSV_LOCAL_H (0x0038u) /**< Local KSV (High) + register offset */ +#define XHDCP1X_CIPHER_REG_KSV_LOCAL_L (0x003Cu) /**< Local KSV (Low) register + offset */ +#define XHDCP1X_CIPHER_REG_KSV_REMOTE_H (0x0040u) /**< Remote KSV (High) + offset */ +#define XHDCP1X_CIPHER_REG_KSV_REMOTE_L (0x0044u) /**< Remote KSV (Low) + register offset */ +#define XHDCP1X_CIPHER_REG_Km_H (0x0048u) /**< Km (High) register + offset */ +#define XHDCP1X_CIPHER_REG_Km_L (0x004Cu) /**< Km (Low) register + offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_CONTROL (0x0050u) /**< Cipher Control register offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_STATUS (0x0054u) /**< Cipher Status register offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_Bx (0x0058u) /**< Cipher Bx register offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_By (0x005Cu) /**< Cipher By register offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_Bz (0x0060u) /**< Cipher Bz register offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_Kx (0x0064u) /**< Cipher Kx register offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_Ky (0x0068u) /**< Cipher Ky register offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_Kz (0x006Cu) /**< Cipher Kz register offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_Mi_H (0x0070u) /**< Cipher Mi (High) register offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_Mi_L (0x0074u) /**< Cipher Mi (Low) register offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_Ri (0x0078u) /**< Cipher Ri register offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_Ro (0x007Cu) /**< Cipher Ro register offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_Mo_H (0x0080u) /**< Cipher Mo (High) register offset */ -#define XHDCP1X_CIPHER_REG_CIPHER_Mo_L (0x0084u) /**< Cipher Mo (Low) register offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_CONTROL \ + (0x0050u) /**< Cipher Control register + offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_STATUS (0x0054u) /**< Cipher Status register + offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_Bx (0x0058u) /**< Cipher Bx register + offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_By (0x005Cu) /**< Cipher By register + offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_Bz (0x0060u) /**< Cipher Bz register + offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_Kx (0x0064u) /**< Cipher Kx register + offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_Ky (0x0068u) /**< Cipher Ky register + offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_Kz (0x006Cu) /**< Cipher Kz register + offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_Mi_H (0x0070u) /**< Cipher Mi (High) + register offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_Mi_L (0x0074u) /**< Cipher Mi (Low) register + offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_Ri (0x0078u) /**< Cipher Ri register + offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_Ro (0x007Cu) /**< Cipher Ro register + offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_Mo_H (0x0080u) /**< Cipher Mo (High) + register offset */ +#define XHDCP1X_CIPHER_REG_CIPHER_Mo_L (0x0084u) /**< Cipher Mo (Low) register + offset */ // HDCP Cipher register bit mask definitions -#define XHDCP1X_CIPHER_BITMASK_TYPE_PROTOCOL (0x03u << 0) /**< Protocol bitmask in Type register */ -#define XHDCP1X_CIPHER_BITMASK_TYPE_DIRECTION (0x01u << 2) /**< Direction bitmask in Type register */ +#define XHDCP1X_CIPHER_BITMASK_TYPE_PROTOCOL \ + (0x03u << 0) /**< Protocol bitmask in + Type register */ +#define XHDCP1X_CIPHER_BITMASK_TYPE_DIRECTION \ + (0x01u << 2) /**< Direction bitmask in + Type register */ -#define XHDCP1X_CIPHER_BITMASK_CONTROL_ENABLE (0x01u << 0) /**< Enable bitmask in Control register */ -#define XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE (0x01u << 1) /**< Update bitmask in Control register */ -#define XHDCP1X_CIPHER_BITMASK_CONTROL_NUM_LANES (0x07u << 4) /**< Num Lanes bitmask in Control register */ -#define XHDCP1X_CIPHER_BITMASK_CONTROL_RESET (0x01u << 31) /**< Reset bitmask in Control register */ +#define XHDCP1X_CIPHER_BITMASK_CONTROL_ENABLE \ + (0x01u << 0) /**< Enable bitmask in + Control register */ +#define XHDCP1X_CIPHER_BITMASK_CONTROL_UPDATE \ + (0x01u << 1) /**< Update bitmask in + Control register */ +#define XHDCP1X_CIPHER_BITMASK_CONTROL_NUM_LANES \ + (0x07u << 4) /**< Num Lanes bitmask in + Control register */ +#define XHDCP1X_CIPHER_BITMASK_CONTROL_RESET \ + (0x01u << 31) /**< Reset bitmask in + Control register */ -#define XHDCP1X_CIPHER_BITMASK_INTERRUPT_LINK_FAIL (0x01u << 0) /**< Link Failure bitmask in Interrupt register(s) */ -#define XHDCP1X_CIPHER_BITMASK_INTERRUPT_Ri_UPDATE (0x01u << 1) /**< Ri bitmask in Interrupt register(s) */ +#define XHDCP1X_CIPHER_BITMASK_INTERRUPT_LINK_FAIL \ + (0x01u << 0) /**< Link Failure bitmask + in Interrupt register(s) */ +#define XHDCP1X_CIPHER_BITMASK_INTERRUPT_Ri_UPDATE \ + (0x01u << 1) /**< Ri bitmask in + Interrupt register(s) */ -#define XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_LOCAL_KSV (0x01u << 0) /**< Read Local KSV bitmask in Key Management Control register */ -#define XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_BEGIN_Km (0x01u << 1) /**< Being Km bitmask in Key Management Control register */ -#define XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_ABORT_Km (0x01u << 2) /**< Abort Km bitmask in Key Management Control register */ -#define XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_SET_SELECT (0x07u << 16) /**< Key Set Select bitmask in Key Management Control register */ +#define XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_LOCAL_KSV \ + (0x01u << 0) /**< Read Local KSV + bitmask in Key Management + Control register */ +#define XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_BEGIN_Km \ + (0x01u << 1) /**< Being Km bitmask in + Key Management Control + register */ +#define XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_ABORT_Km \ + (0x01u << 2) /**< Abort Km bitmask in + Key Management Control + register */ +#define XHDCP1X_CIPHER_BITMASK_KEYMGMT_CONTROL_SET_SELECT \ + (0x07u << 16) /**< Key Set Select + bitmask in Key Management + Control register */ -#define XHDCP1X_CIPHER_BITMASK_KEYMGMT_STATUS_KSV_READY (0x01u << 0) /**< Local KSV ready bitmask in Key Management Status register */ -#define XHDCP1X_CIPHER_BITMASK_KEYMGMT_STATUS_Km_READY (0x01u << 1) /**< Km Value ready bitmask in Key Management Status register */ +#define XHDCP1X_CIPHER_BITMASK_KEYMGMT_STATUS_KSV_READY \ + (0x01u << 0) /**< Local KSV ready + bitmask in Key Management Status + register */ +#define XHDCP1X_CIPHER_BITMASK_KEYMGMT_STATUS_Km_READY \ + (0x01u << 1) /**< Km Value ready + bitmask in Key Management Status + register */ -#define XHDCP1X_CIPHER_BITMASK_CIPHER_CONTROL_XOR_ENABLE (0x01u << 0) /**< XOR Enable bitmask in Cipher Control register */ -#define XHDCP1X_CIPHER_BITMASK_CIPHER_CONTROL_REQUEST (0x07u << 8) /**< Request bitmask in Cipher Control register */ +#define XHDCP1X_CIPHER_BITMASK_CIPHER_CONTROL_XOR_ENABLE \ + (0x01u << 0) /**< XOR Enable bitmask + in Cipher Control register */ +#define XHDCP1X_CIPHER_BITMASK_CIPHER_CONTROL_REQUEST \ + (0x07u << 8) /**< Request bitmask in + Cipher Control register */ -#define XHDCP1X_CIPHER_BITMASK_CIPHER_STATUS_XOR_IN_PROG (0x01u << 0) /**< XOR In Progress bitmask in Cipher Status register */ -#define XHDCP1X_CIPHER_BITMASK_CIPHER_STATUS_REQUEST_IN_PROG (0x07u << 8) /**< Request In Progress bitmask in Cipher Status register */ +#define XHDCP1X_CIPHER_BITMASK_CIPHER_STATUS_XOR_IN_PROG \ + (0x01u << 0) /**< XOR In Progress + bitmask in Cipher Status + register */ +#define XHDCP1X_CIPHER_BITMASK_CIPHER_STATUS_REQUEST_IN_PROG \ + (0x07u << 8) /**< Request In Progress + bitmask in Cipher Status + register */ // HDCP Cipher register bit value definitions -#define XHDCP1X_CIPHER_VALUE_TYPE_PROTOCOL_DP (0x00u << 0) /**< DP Protocol value in Type register */ -#define XHDCP1X_CIPHER_VALUE_TYPE_PROTOCOL_HDMI (0x01u << 0) /**< HDMI Protocol value in Type register */ +#define XHDCP1X_CIPHER_VALUE_TYPE_PROTOCOL_DP \ + (0x00u << 0) /**< DP Protocol value in + Type register */ +#define XHDCP1X_CIPHER_VALUE_TYPE_PROTOCOL_HDMI \ + (0x01u << 0) /**< HDMI Protocol value + in Type register */ -#define XHDCP1X_CIPHER_VALUE_TYPE_DIRECTION_RX (0x00u << 2) /**< RX Direction value in Type register */ -#define XHDCP1X_CIPHER_VALUE_TYPE_DIRECTION_TX (0x01u << 2) /**< TX Direction value in Type register */ +#define XHDCP1X_CIPHER_VALUE_TYPE_DIRECTION_RX \ + (0x00u << 2) /**< RX Direction value + in Type register */ +#define XHDCP1X_CIPHER_VALUE_TYPE_DIRECTION_TX \ + (0x01u << 2) /**< TX Direction value + in Type register */ -#define XHDCP1X_CIPHER_VALUE_CIPHER_CONTROL_REQUEST_BLOCK (0x01u << 8) /**< Block Request value in Cipher Control register */ -#define XHDCP1X_CIPHER_VALUE_CIPHER_CONTROL_REQUEST_REKEY (0x01u << 9) /**< ReKey Request value in Cipher Control register */ -#define XHDCP1X_CIPHER_VALUE_CIPHER_CONTROL_REQUEST_RNG (0x01u << 10) /**< RNG Request value in Cipher Control register */ +#define XHDCP1X_CIPHER_VALUE_CIPHER_CONTROL_REQUEST_BLOCK \ + (0x01u << 8) /**< Block Request value + in Cipher Control register */ +#define XHDCP1X_CIPHER_VALUE_CIPHER_CONTROL_REQUEST_REKEY \ + (0x01u << 9) /**< ReKey Request value + in Cipher Control register */ +#define XHDCP1X_CIPHER_VALUE_CIPHER_CONTROL_REQUEST_RNG \ + (0x01u << 10) /**< RNG Request value in + Cipher Control register */ /**************************** Type Definitions *******************************/ diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher_intr.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher_intr.c index 1a3bfd69..192cdf5a 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher_intr.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher_intr.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,13 +42,14 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ /***************************** Include Files *********************************/ -#include "xhdcp1x_cipher_hw.h" + +#include "xhdcp1x_hw.h" #include "xhdcp1x_cipher.h" #include "xil_types.h" @@ -58,17 +59,16 @@ /***************** Macros (Inline Functions) Definitions *********************/ -#define RegRead(InstancePtr, Offset) \ +#define RegRead(InstancePtr, Offset) \ XHdcp1x_CipherReadReg(InstancePtr->CfgPtr->BaseAddress, Offset) -#define RegWrite(InstancePtr, Offset, Value) \ +#define RegWrite(InstancePtr, Offset, Value) \ XHdcp1x_CipherWriteReg(InstancePtr->CfgPtr->BaseAddress, Offset, Value) /************************** Function Definitions *****************************/ /*****************************************************************************/ /** -* * This function installs an asynchronous callback function for the given * HandlerType: * @@ -96,7 +96,6 @@ int XHdcp1x_CipherSetCallback(XHdcp1x_Cipher *InstancePtr, u32 HandlerType, XHdcp1x_Callback CallbackFunc, void *CallbackRef) { - /* Locals */ u32 Status = XST_SUCCESS; /* Verify arguments. */ @@ -107,43 +106,40 @@ int XHdcp1x_CipherSetCallback(XHdcp1x_Cipher *InstancePtr, u32 HandlerType, /* Check for handler type */ switch (HandlerType) { - - /* Link Failure Callback */ - case (XHDCP1X_CIPHER_HANDLER_LINK_FAILURE): - InstancePtr->LinkFailCallback = CallbackFunc; - InstancePtr->LinkFailRef = CallbackRef; - InstancePtr->IsLinkFailCallbackSet = (TRUE); - break; + /* Link Failure Callback */ + case (XHDCP1X_CIPHER_HANDLER_LINK_FAILURE): + InstancePtr->LinkFailCallback = CallbackFunc; + InstancePtr->LinkFailRef = CallbackRef; + InstancePtr->IsLinkFailCallbackSet = (TRUE); + break; /* Ri Update Callback */ - case (XHDCP1X_CIPHER_HANDLER_Ri_UPDATE): - InstancePtr->RiUpdateCallback = CallbackFunc; - InstancePtr->RiUpdateRef = CallbackRef; - InstancePtr->IsRiUpdateCallbackSet = (TRUE); - break; + case (XHDCP1X_CIPHER_HANDLER_Ri_UPDATE): + InstancePtr->RiUpdateCallback = CallbackFunc; + InstancePtr->RiUpdateRef = CallbackRef; + InstancePtr->IsRiUpdateCallbackSet = (TRUE); + break; - default: - Status = (XST_INVALID_PARAM); - break; + default: + Status = (XST_INVALID_PARAM); + break; } - /* Return */ return (Status); } /*****************************************************************************/ /** +* This function enables/disables the reporting of link check state changes. * -* This function enables/disables the reporting of link check state changes -* -* @param InstancePtr the cipher core instance -* @param IsEnabled enable/disable link state change notifications +* @param InstancePtr is the cipher core instance. +* @param IsEnabled enables/disables link state change notifications. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_CipherSetLinkStateCheck(XHdcp1x_Cipher *InstancePtr, int IsEnabled) @@ -156,7 +152,6 @@ int XHdcp1x_CipherSetLinkStateCheck(XHdcp1x_Cipher *InstancePtr, int IsEnabled) /* Check DP receive */ if (XHdcp1x_CipherIsDP(InstancePtr) && XHdcp1x_CipherIsRX(InstancePtr)) { - u32 Val = 0; /* Clear any pending link state failure interrupt */ @@ -182,17 +177,16 @@ int XHdcp1x_CipherSetLinkStateCheck(XHdcp1x_Cipher *InstancePtr, int IsEnabled) /*****************************************************************************/ /** +* This function enables/disables the reporting of Ri update notifications. * -* This function enables/disables the reporting of Ri update notifications -* -* @param InstancePtr the cipher core instance -* @param IsEnabled enable/disable Ri update notifications +* @param InstancePtr is the cipher core instance. +* @param IsEnabled enables/disables Ri update notifications. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_CipherSetRiUpdate(XHdcp1x_Cipher *InstancePtr, int IsEnabled) @@ -204,7 +198,6 @@ int XHdcp1x_CipherSetRiUpdate(XHdcp1x_Cipher *InstancePtr, int IsEnabled) /* Check HDMI receive */ if (XHdcp1x_CipherIsHDMI(InstancePtr)) { - u32 Val = 0; /* Clear any pending link state failure interrupt */ @@ -230,21 +223,18 @@ int XHdcp1x_CipherSetRiUpdate(XHdcp1x_Cipher *InstancePtr, int IsEnabled) /*****************************************************************************/ /** +* This function is the interrupt handler for the cipher core driver. * -* This function is the interrupt handler for the cipher core driver +* @param InstancePtr is the cipher core instance. * -* @param InstancePtr the cipher core instance +* @return None. * -* @return -* void -* -* @note -* none +* @note None. * ******************************************************************************/ void XHdcp1x_CipherHandleInterrupt(void *InstancePtr) { - XHdcp1x_Cipher *HdcpCipherPtr = (XHdcp1x_Cipher *) InstancePtr; + XHdcp1x_Cipher *HdcpCipherPtr = (XHdcp1x_Cipher *)InstancePtr; u32 Pending = 0; /* Verify arguments */ @@ -257,7 +247,6 @@ void XHdcp1x_CipherHandleInterrupt(void *InstancePtr) /* Check for pending */ if (Pending != 0) { - /* Clear Pending */ RegWrite(HdcpCipherPtr, XHDCP1X_CIPHER_REG_INTERRUPT_STATUS, Pending); @@ -267,7 +256,6 @@ void XHdcp1x_CipherHandleInterrupt(void *InstancePtr) /* Check for link integrity failure */ if (Pending & XHDCP1X_CIPHER_BITMASK_INTERRUPT_LINK_FAIL) { - /* Invoke callback if set */ if (HdcpCipherPtr->IsLinkFailCallbackSet) (*HdcpCipherPtr->LinkFailCallback)( @@ -276,13 +264,10 @@ void XHdcp1x_CipherHandleInterrupt(void *InstancePtr) /* Check for change to Ri register */ if (Pending & XHDCP1X_CIPHER_BITMASK_INTERRUPT_Ri_UPDATE) { - /* Invoke callback if set */ if (HdcpCipherPtr->IsRiUpdateCallbackSet) (*HdcpCipherPtr->RiUpdateCallback)( HdcpCipherPtr->RiUpdateRef); } } - - return; } diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher_selftest.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher_selftest.c index 87886b39..b8561ac3 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher_selftest.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_cipher_selftest.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,12 +42,12 @@ * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- * 1.00 07/16/15 Initial release. -* 1.01 07/23/15 Additional documentation and formating * * ******************************************************************************/ /***************************** Include Files *********************************/ + #include "xhdcp1x_cipher.h" #include "xil_assert.h" @@ -70,16 +70,15 @@ /*****************************************************************************/ /** +* This function self tests an hdcp cipher core. * -* This function self tests an hdcp cipher core -* -* @param InstancePtr the cipher core to test +* @param InstancePtr is the cipher core to test. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_CipherSelfTest(XHdcp1x_Cipher *InstancePtr) @@ -98,27 +97,29 @@ int XHdcp1x_CipherSelfTest(XHdcp1x_Cipher *InstancePtr) Value = XHdcp1x_CipherReadReg(Base, XHDCP1X_CIPHER_REG_VERSION); /* Confirm the version is reasonable */ - if ((Value != 0u) && (Value != ((u32) (-1)))) { - + if ((Value != 0u) && (Value != ((u32)(-1)))) { const XHdcp1x_Config *CfgPtr = InstancePtr->CfgPtr; int IsRx = FALSE; int IsHdmi = FALSE; /* Determine isRx */ - Value = XHdcp1x_CipherReadReg(Base, XHDCP1X_CIPHER_REG_TYPE); + Value = XHdcp1x_CipherReadReg(Base, XHDCP1X_CIPHER_REG_TYPE); Value &= XHDCP1X_CIPHER_BITMASK_TYPE_DIRECTION; - if (Value == XHDCP1X_CIPHER_VALUE_TYPE_DIRECTION_RX) + if (Value == XHDCP1X_CIPHER_VALUE_TYPE_DIRECTION_RX) { IsRx = TRUE; + } /* Determine isHdmi */ - Value = XHdcp1x_CipherReadReg(Base, XHDCP1X_CIPHER_REG_TYPE); + Value = XHdcp1x_CipherReadReg(Base, XHDCP1X_CIPHER_REG_TYPE); Value &= XHDCP1X_CIPHER_BITMASK_TYPE_PROTOCOL; - if (Value == XHDCP1X_CIPHER_VALUE_TYPE_PROTOCOL_HDMI) + if (Value == XHDCP1X_CIPHER_VALUE_TYPE_PROTOCOL_HDMI) { IsHdmi = TRUE; + } /* Confirm direction and protocol match */ - if (((IsRx == CfgPtr->IsRx)) && ((IsHdmi == CfgPtr->IsHDMI))) + if (((IsRx == CfgPtr->IsRx)) && ((IsHdmi == CfgPtr->IsHDMI))) { Status = XST_SUCCESS; + } } return (Status); diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_debug.h b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_debug.h index 1a2ee525..7d460a02 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_debug.h +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_debug.h @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -41,10 +41,11 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ + #ifndef XHDCP1X_DEBUG_H /**< Prevent circular inclusions by using protection macros */ #define XHDCP1X_DEBUG_H @@ -54,25 +55,27 @@ extern "C" { #endif /***************************** Include Files *********************************/ + #include "xhdcp1x.h" /************************** Constant Definitions *****************************/ /***************** Macros (Inline Functions) Definitions *********************/ -#define XHDCP1X_DEBUG_PRINTF if (XHdcp1xDebugPrintf != NULL) XHdcp1xDebugPrintf -#define XHDCP1X_DEBUG_LOGMSG if (XHdcp1xDebugLogMsg != NULL) XHdcp1xDebugLogMsg + +#define XHDCP1X_DEBUG_PRINTF if (XHdcp1xDebugPrintf != NULL) XHdcp1xDebugPrintf +#define XHDCP1X_DEBUG_LOGMSG if (XHdcp1xDebugLogMsg != NULL) XHdcp1xDebugLogMsg /**************************** Type Definitions *******************************/ /************************** Function Prototypes ******************************/ -/************************* External Declarations******************************/ -extern XHdcp1x_Printf XHdcp1xDebugPrintf; -extern XHdcp1x_LogMsg XHdcp1xDebugLogMsg; +/************************* External Declarations *****************************/ + +extern XHdcp1x_Printf XHdcp1xDebugPrintf; +extern XHdcp1x_LogMsg XHdcp1xDebugLogMsg; #ifdef __cplusplus } #endif - #endif /* XHDCP1X_DEBUG_H */ diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_intr.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_intr.c index 6038e20e..dfb14b96 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_intr.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_intr.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,12 +42,13 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ /***************************** Include Files *********************************/ + #include "xhdcp1x.h" #include "xhdcp1x_cipher.h" #include "xil_types.h" @@ -62,22 +63,19 @@ /*****************************************************************************/ /** +* This function is the cipher interrupt handler for the HDCP module. * -* This function is the cipher interrupt handler for the HDCP module +* @param InstancePtr is the device instance that just interrupted. * -* @param InstancePtr the device instance that just interrupted +* @return None. * -* @return -* void -* -* @note -* This function just forwards the interrupt along to the corresponding -* cipher core. +* @note This function just forwards the interrupt along to the +* corresponding cipher core. * ******************************************************************************/ void XHdcp1x_CipherIntrHandler(void *InstancePtr) { - XHdcp1x* HdcpPtr = InstancePtr; + XHdcp1x *HdcpPtr = InstancePtr; /* Verify arguments */ Xil_AssertVoid(HdcpPtr != NULL); @@ -89,23 +87,20 @@ void XHdcp1x_CipherIntrHandler(void *InstancePtr) /*****************************************************************************/ /** +* This function is the port interrupt handler for the HDCP module. * -* This function is the port interrupt handler for the HDCP module +* @param InstancePtr is the device instance that just interrupted. +* @param IntCause is the interrupt cause bit map. * -* @param InstancePtr the device instance that just interrupted -* @param IntCause the interrupt cause bit map +* @return None. * -* @return -* void -* -* @note -* This function just forwards the interrupt along to the corresponding -* cipher core. +* @note This function just forwards the interrupt along to the +* corresponding cipher core. * ******************************************************************************/ void XHdcp1x_PortIntrHandler(void *InstancePtr, u32 IntCause) { - XHdcp1x* HdcpPtr = InstancePtr; + XHdcp1x *HdcpPtr = InstancePtr; /* Verify arguments */ Xil_AssertVoid(HdcpPtr != NULL); diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_platform.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_platform.c index 478b7364..750d813e 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_platform.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_platform.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,12 +42,13 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ /***************************** Include Files *********************************/ + #include "xhdcp1x.h" #include "xhdcp1x_platform.h" #include "xil_types.h" @@ -59,26 +60,24 @@ /**************************** Type Definitions *******************************/ /************************** Extern Declarations ******************************/ -extern XHdcp1x_KsvRevokeCheck XHdcp1xKsvRevokeCheck; -extern XHdcp1x_TimerStart XHdcp1xTimerStart; -extern XHdcp1x_TimerStop XHdcp1xTimerStop; -extern XHdcp1x_TimerDelay XHdcp1xTimerDelay; + +extern XHdcp1x_KsvRevokeCheck XHdcp1xKsvRevokeCheck; +extern XHdcp1x_TimerStart XHdcp1xTimerStart; +extern XHdcp1x_TimerStop XHdcp1xTimerStop; +extern XHdcp1x_TimerDelay XHdcp1xTimerDelay; /************************** Function Prototypes ******************************/ /*****************************************************************************/ /** +* This function checks a KSV value to determine if it has been revoked or not. * -* This function checks a KSV value to determine if it has been revoked or not +* @param InstancePtr is the HDCP interface. +* @param Ksv is the KSV to check. * -* @param InstancePtr the hdcp interface -* @param Ksv the KSV to check +* @return Truth value indicating the KSV is revoked (TRUE) or not (FALSE). * -* @return -* Truth value indicating the KSV is revoked (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PlatformIsKsvRevoked(const XHdcp1x *InstancePtr, u64 Ksv) @@ -98,17 +97,16 @@ int XHdcp1x_PlatformIsKsvRevoked(const XHdcp1x *InstancePtr, u64 Ksv) /*****************************************************************************/ /** +* This function starts a timer on behalf of an HDCP interface. * -* This function starts a timer on behalf of an hdcp interface -* -* @param InstancePtr the hdcp interface -* @param TimeoutInMs the duration of the timer in milliseconds +* @param InstancePtr is the hdcp interface. +* @param TimeoutInMs is the duration of the timer in milliseconds. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PlatformTimerStart(XHdcp1x *InstancePtr, u16 TimeoutInMs) @@ -126,19 +124,17 @@ int XHdcp1x_PlatformTimerStart(XHdcp1x *InstancePtr, u16 TimeoutInMs) return (Status); } - /*****************************************************************************/ /** +* This function stop a timer on behalf of an HDCP interface. * -* This function stop a timer on behalf of an hdcp interface -* -* @param InstancePtr the hdcp interface +* @param InstancePtr is the HDCP interface. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PlatformTimerStop(XHdcp1x *InstancePtr) @@ -156,20 +152,18 @@ int XHdcp1x_PlatformTimerStop(XHdcp1x *InstancePtr) return (Status); } - /*****************************************************************************/ /** +* This function busy waits on a timer for a number of milliseconds. * -* This function busy waits on a timer for a number of milliseconds -* -* @param InstancePtr the hdcp interface -* @param DelayInMs the delay time in milliseconds +* @param InstancePtr is the hdcp interface. +* @param DelayInMs is the delay time in milliseconds. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PlatformTimerBusy(XHdcp1x *InstancePtr, u16 DelayInMs) diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_platform.h b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_platform.h index ee848c68..c6d4dfbc 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_platform.h +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_platform.h @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -41,10 +41,11 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ + #ifndef XHDCP1X_PLATFORM_H /**< Prevent circular inclusions by using protection macros */ #define XHDCP1X_PLATFORM_H @@ -54,6 +55,7 @@ extern "C" { #endif /***************************** Include Files *********************************/ + #include "xhdcp1x.h" #include "xil_types.h" @@ -64,6 +66,7 @@ extern "C" { /**************************** Type Definitions *******************************/ /************************** Function Prototypes ******************************/ + int XHdcp1x_PlatformIsKsvRevoked(const XHdcp1x *InstancePtr, u64 Ksv); int XHdcp1x_PlatformTimerStart(XHdcp1x *InstancePtr, u16 TimeoutInMs); @@ -74,5 +77,4 @@ int XHdcp1x_PlatformTimerBusy(XHdcp1x *InstancePtr, u16 DelayInMs); } #endif - #endif /* XHDCP1X_PLATFORM_H */ diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port.c index 271d5bcd..ff57784f 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -28,7 +28,7 @@ * in advertising or otherwise to promote the sale, use or other dealings in * this Software without prior written authorization from Xilinx. * -*****************************************************************************/ +******************************************************************************/ /*****************************************************************************/ /** * @@ -41,13 +41,13 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. -* 1.01 07/23/15 Additional documentation and formating +* 1.00 fidus 07/16/15 Initial release. * * *****************************************************************************/ /***************************** Include Files *********************************/ + #include #include #include "xhdcp1x_port.h" @@ -56,6 +56,7 @@ #include "xparameters.h" /************************** Constant Definitions *****************************/ + #if defined(XPAR_XHDMI_TX_NUM_INSTANCES) && (XPAR_XHDMI_TX_NUM_INSTANCES > 0) #define INCLUDE_HDMI_TX #endif @@ -86,20 +87,315 @@ extern const XHdcp1x_PortPhyIfAdaptor XHdcp1x_PortDpTxAdaptor; extern const XHdcp1x_PortPhyIfAdaptor XHdcp1x_PortDpRxAdaptor; #endif +/*************************** Function Prototypes *****************************/ + +static const XHdcp1x_PortPhyIfAdaptor *DetermineAdaptor( + const XHdcp1x_Port *InstancePtr); + /************************** Function Definitions *****************************/ /*****************************************************************************/ /** +* This function initializes a port device. * -* This function determines the adaptor for a specified port device -* -* @param InstancePtr the device whose adaptor is to be determined +* @param InstancePtr is the device to initialize. +* @param CfgPtr is the HDCP configuration structure. +* @param PhyIfPtr is pointer to the underlying physical interface. * * @return -* Pointer to the adaptor table. NULL if not found. +* - XST_SUCCESS if successful. +* - XST_NO_FEATURE if the port lacks an Init function. * -* @note -* None. +* @note None. +* +******************************************************************************/ +int XHdcp1x_PortCfgInitialize(XHdcp1x_Port *InstancePtr, + const XHdcp1x_Config *CfgPtr, void *PhyIfPtr) +{ + int Status = XST_SUCCESS; + + /* Verify arguments. */ + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(CfgPtr != NULL); + Xil_AssertNonvoid(PhyIfPtr != NULL); + Xil_AssertNonvoid(InstancePtr->IsReady != XIL_COMPONENT_IS_READY); + + /* Initialize InstancePtr */ + memset(InstancePtr, 0, sizeof(XHdcp1x_Port)); + InstancePtr->CfgPtr = CfgPtr; + InstancePtr->PhyIfPtr = PhyIfPtr; + InstancePtr->Adaptor = DetermineAdaptor(InstancePtr); + + /* Sanity Check */ + if (InstancePtr->Adaptor == NULL) { + Status = XST_NO_FEATURE; + } + /* Invoke adaptor function if present */ + else if (InstancePtr->Adaptor->Init != NULL) { + Status = (*(InstancePtr->Adaptor->Init))(InstancePtr); + } + + /* Set IsReady */ + if (Status == XST_SUCCESS) { + InstancePtr->IsReady = XIL_COMPONENT_IS_READY; + } + + return (Status); +} + +/*****************************************************************************/ +/** +* This function enables a port device. +* +* @param InstancePtr is the device to enables. +* +* @return +* - XST_SUCCESS if successful. +* - XST_NO_FEATURE if the port lacks an Enable function. +* +* @note None. +* +******************************************************************************/ +int XHdcp1x_PortEnable(XHdcp1x_Port *InstancePtr) +{ + const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; + int Status = XST_SUCCESS; + + /* Verify arguments. */ + Xil_AssertNonvoid(InstancePtr != NULL); + + /* Determine Adaptor */ + Adaptor = InstancePtr->Adaptor; + + /* Sanity Check */ + if (Adaptor == NULL) { + Status = XST_NO_FEATURE; + } + /* Invoke adaptor function if present */ + else if (Adaptor->Enable != NULL) { + Status = (*(Adaptor->Enable))(InstancePtr); + } + + return (Status); +} + +/*****************************************************************************/ +/** +* This function disables a port device. +* +* @param InstancePtr is the device to disables. +* +* @return +* - XST_SUCCESS if successful. +* - XST_NO_FEATURE if the port lacks a Disable function. +* +* @note None. +* +******************************************************************************/ +int XHdcp1x_PortDisable(XHdcp1x_Port *InstancePtr) +{ + const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; + int Status = XST_SUCCESS; + + /* Verify arguments. */ + Xil_AssertNonvoid(InstancePtr != NULL); + + /* Determine Adaptor */ + Adaptor = InstancePtr->Adaptor; + + /* Sanity Check */ + if (Adaptor == NULL) { + Status = XST_NO_FEATURE; + } + /* Invoke adaptor function if present */ + else if (Adaptor->Disable != NULL) { + Status = (*(Adaptor->Disable))(InstancePtr); + } + + return (Status); +} + +/*****************************************************************************/ +/** +* This function queries a port device to determine if hdcp is supported. +* +* @param InstancePtr is the device to query. +* +* @return Truth value. +* +* @note None. +* +******************************************************************************/ +int XHdcp1x_PortIsCapable(const XHdcp1x_Port *InstancePtr) +{ + const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; + int IsCapable = FALSE; + + /* Verify arguments. */ + Xil_AssertNonvoid(InstancePtr != NULL); + + /* Determine Adaptor */ + Adaptor = InstancePtr->Adaptor; + + /* Invoke adaptor function if present */ + if ((Adaptor != NULL) && (Adaptor->IsCapable != NULL)) { + IsCapable = (*(Adaptor->IsCapable))(InstancePtr); + } + + return (IsCapable); +} + +/*****************************************************************************/ +/** +* This function queries a port device to determine if it is connected to a +* repeater. +* +* @param InstancePtr is the device to query. +* +* @return Truth value. +* +* @note None. +* +******************************************************************************/ +int XHdcp1x_PortIsRepeater(const XHdcp1x_Port *InstancePtr) +{ + const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; + int IsRepeater = FALSE; + + /* Verify arguments. */ + Xil_AssertNonvoid(InstancePtr != NULL); + + /* Determine Adaptor */ + Adaptor = InstancePtr->Adaptor; + + /* Invoke adaptor function if present */ + if ((Adaptor != NULL) && (Adaptor->IsRepeater != NULL)) { + IsRepeater = (*(Adaptor->IsRepeater))(InstancePtr); + } + + return (IsRepeater); +} + +/*****************************************************************************/ +/** +* This function retrieves the repeater information from the connected device. +* +* @param InstancePtr is the device to query. +* @param InfoPtr is the repeater info. +* +* @return +* - XST_SUCCESS if successful. +* - XST_NO_FEATURE if the port lacks a GetRepeaterInfo function. +* +* @note None. +* +******************************************************************************/ +int XHdcp1x_PortGetRepeaterInfo(XHdcp1x_Port *InstancePtr, u16 *InfoPtr) +{ + const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; + int Status = XST_SUCCESS; + + /* Verify arguments. */ + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(InfoPtr != NULL); + + /* Determine Adaptor */ + Adaptor = InstancePtr->Adaptor; + + /* Sanity Check */ + if (Adaptor == NULL) { + Status = XST_NO_FEATURE; + } + /* Invoke adaptor function if present */ + else if (Adaptor->GetRepeaterInfo != NULL) { + Status = (*(Adaptor->GetRepeaterInfo))(InstancePtr, InfoPtr); + } + + return (Status); +} + +/*****************************************************************************/ +/** +* This function reads a register from a HDCP port device. +* +* @param InstancePtr is the device to read from. +* @param Offset is the offset to start reading from. +* @param Buf is the buffer to copy the data read. +* @param BufSize is the size of the buffer. +* +* @return The number of bytes read. +* +* @note None. +* +******************************************************************************/ +int XHdcp1x_PortRead(const XHdcp1x_Port *InstancePtr, u8 Offset, void *Buf, + u32 BufSize) +{ + const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; + int NumRead = 0; + + /* Verify arguments. */ + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(Buf != NULL); + + /* Determine Adaptor */ + Adaptor = InstancePtr->Adaptor; + + /* Invoke adaptor function if present */ + if ((Adaptor != NULL) && (Adaptor->Read != NULL)) { + NumRead = (*(Adaptor->Read))(InstancePtr, Offset, Buf, + BufSize); + } + + return (NumRead); +} + +/*****************************************************************************/ +/** +* This function writes a register within a HDCP port device. +* +* @param InstancePtr is the device to write to. +* @param Offset is the offset to start writing at. +* @param Buf is the buffer containing the data to write. +* @param BufSize is the size of the buffer. +* +* @return The number of bytes written. +* +* @note None. +* +******************************************************************************/ +int XHdcp1x_PortWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const void *Buf, + u32 BufSize) +{ + const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; + int NumWritten = 0; + + /* Verify arguments. */ + Xil_AssertNonvoid(InstancePtr != NULL); + Xil_AssertNonvoid(Buf != NULL); + + /* Determine Adaptor */ + Adaptor = InstancePtr->Adaptor; + + /* Invoke adaptor function if present */ + if ((Adaptor != NULL) && (Adaptor->Write != NULL)) { + NumWritten = (*(Adaptor->Write))(InstancePtr, Offset, Buf, + BufSize); + } + + return (NumWritten); +} + +/*****************************************************************************/ +/** +* +* This function determines the adaptor for a specified port device. +* +* @param InstancePtr is the device whose adaptor is to be determined. +* +* @return A pointer to the adaptor table. NULL if not found. +* +* @note None. * ******************************************************************************/ static const XHdcp1x_PortPhyIfAdaptor *DetermineAdaptor( @@ -142,312 +438,3 @@ static const XHdcp1x_PortPhyIfAdaptor *DetermineAdaptor( return (Adaptor); } - -/*****************************************************************************/ -/** -* -* This function initializes a port device -* -* @param InstancePtr the device to initialize -* @param CfgPtr the hdcp configuration structure -* @param PhyIfPtr pointer to the underlying physical interface -* -* @return -* XST_SUCCESS if successful. -* -* @note -* None. -* -******************************************************************************/ -int XHdcp1x_PortCfgInitialize(XHdcp1x_Port *InstancePtr, - const XHdcp1x_Config *CfgPtr, void* PhyIfPtr) -{ - int Status = XST_SUCCESS; - - /* Verify arguments. */ - Xil_AssertNonvoid(InstancePtr != NULL); - Xil_AssertNonvoid(CfgPtr != NULL); - Xil_AssertNonvoid(PhyIfPtr != NULL); - Xil_AssertNonvoid(InstancePtr->IsReady != XIL_COMPONENT_IS_READY); - - /* Initialize InstancePtr */ - memset(InstancePtr, 0, sizeof(XHdcp1x_Port)); - InstancePtr->CfgPtr = CfgPtr; - InstancePtr->PhyIfPtr = PhyIfPtr; - InstancePtr->Adaptor = DetermineAdaptor(InstancePtr); - - /* Sanity Check */ - if (InstancePtr->Adaptor == NULL) { - Status = XST_NO_FEATURE; - } - /* Invoke adaptor function if present */ - else if (InstancePtr->Adaptor->Init != NULL) { - Status = (*(InstancePtr->Adaptor->Init))(InstancePtr); - } - - /* Set IsReady */ - if (Status == XST_SUCCESS) { - InstancePtr->IsReady = XIL_COMPONENT_IS_READY; - } - - return (Status); -} - -/*****************************************************************************/ -/** -* -* This function enables a port device -* -* @param InstancePtr the device to enables -* -* @return -* XST_SUCCESS if successful. -* -* @note -* None. -* -******************************************************************************/ -int XHdcp1x_PortEnable(XHdcp1x_Port *InstancePtr) -{ - const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; - int Status = XST_SUCCESS; - - /* Verify arguments. */ - Xil_AssertNonvoid(InstancePtr != NULL); - - /* Determine Adaptor */ - Adaptor = InstancePtr->Adaptor; - - /* Sanity Check */ - if (Adaptor == NULL) { - Status = XST_NO_FEATURE; - } - /* Invoke adaptor function if present */ - else if (Adaptor->Enable != NULL) { - Status = (*(Adaptor->Enable))(InstancePtr); - } - - return (Status); -} - -/*****************************************************************************/ -/** -* -* This function disables a port device -* -* @param InstancePtr the device to disables -* -* @return -* XST_SUCCESS if successful. -* -* @note -* None. -* -******************************************************************************/ -int XHdcp1x_PortDisable(XHdcp1x_Port *InstancePtr) -{ - const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; - int Status = XST_SUCCESS; - - /* Verify arguments. */ - Xil_AssertNonvoid(InstancePtr != NULL); - - /* Determine Adaptor */ - Adaptor = InstancePtr->Adaptor; - - /* Sanity Check */ - if (Adaptor == NULL) { - Status = XST_NO_FEATURE; - } - /* Invoke adaptor function if present */ - else if (Adaptor->Disable != NULL) { - Status = (*(Adaptor->Disable))(InstancePtr); - } - - return (Status); -} - -/*****************************************************************************/ -/** -* -* This function queries a port device to determine if hdcp is supported -* -* @param InstancePtr the device to query -* -* @return -* Truth value -* -* @note -* None. -* -******************************************************************************/ -int XHdcp1x_PortIsCapable(const XHdcp1x_Port *InstancePtr) -{ - const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; - int IsCapable = FALSE; - - /* Verify arguments. */ - Xil_AssertNonvoid(InstancePtr != NULL); - - /* Determine Adaptor */ - Adaptor = InstancePtr->Adaptor; - - /* Invoke adaptor function if present */ - if ((Adaptor != NULL) && (Adaptor->IsCapable != NULL)) { - IsCapable = (*(Adaptor->IsCapable))(InstancePtr); - } - - return (IsCapable); -} - -/*****************************************************************************/ -/** -* -* This function queries a port device to determine if it is connected to a -* repeater. -* -* @param InstancePtr the device to query -* -* @return -* Truth value -* -* @note -* None. -* -******************************************************************************/ -int XHdcp1x_PortIsRepeater(const XHdcp1x_Port *InstancePtr) -{ - const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; - int IsRepeater = FALSE; - - /* Verify arguments. */ - Xil_AssertNonvoid(InstancePtr != NULL); - - /* Determine Adaptor */ - Adaptor = InstancePtr->Adaptor; - - /* Invoke adaptor function if present */ - if ((Adaptor != NULL) && (Adaptor->IsRepeater != NULL)) { - IsRepeater = (*(Adaptor->IsRepeater))(InstancePtr); - } - - return (IsRepeater); -} - -/*****************************************************************************/ -/** -* -* This function retrieves the repeater information from the connected device -* -* @param InstancePtr the device to query -* @param InfoPtr the repeater info -* -* @return -* XST_SUCCESS if successful. -* -* @note -* None. -* -******************************************************************************/ -int XHdcp1x_PortGetRepeaterInfo(XHdcp1x_Port *InstancePtr, u16 *InfoPtr) -{ - const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; - int Status = XST_SUCCESS; - - /* Verify arguments. */ - Xil_AssertNonvoid(InstancePtr != NULL); - Xil_AssertNonvoid(InfoPtr != NULL); - - /* Determine Adaptor */ - Adaptor = InstancePtr->Adaptor; - - /* Sanity Check */ - if (Adaptor == NULL) { - Status = XST_NO_FEATURE; - } - /* Invoke adaptor function if present */ - else if (Adaptor->GetRepeaterInfo != NULL) { - Status = (*(Adaptor->GetRepeaterInfo))(InstancePtr, InfoPtr); - } - - return (Status); -} - -/*****************************************************************************/ -/** -* -* This function reads a register from a hdcp port device -* -* @param InstancePtr the device to read from -* @param Offset the offset to start reading from -* @param Buf the buffer to copy the data read -* @param BufSize the size of the buffer -* -* @return -* The number of bytes read -* -* @note -* None. -* -******************************************************************************/ -int XHdcp1x_PortRead(const XHdcp1x_Port *InstancePtr, u8 Offset, void *Buf, - u32 BufSize) -{ - const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; - int NumRead = 0; - - /* Verify arguments. */ - Xil_AssertNonvoid(InstancePtr != NULL); - Xil_AssertNonvoid(Buf != NULL); - - /* Determine Adaptor */ - Adaptor = InstancePtr->Adaptor; - - /* Invoke adaptor function if present */ - if ((Adaptor != NULL) && (Adaptor->Read != NULL)) { - NumRead = (*(Adaptor->Read))(InstancePtr, Offset, Buf, - BufSize); - } - - /* Return */ - return (NumRead); -} - -/*****************************************************************************/ -/** -* -* This function writes a register within a hdcp port device -* -* @param InstancePtr the device to write to -* @param Offset the offset to start writing at -* @param Buf the buffer containing the data to write -* @param BufSize the size of the buffer -* -* @return -* The number of bytes written -* -* @note -* None. -* -******************************************************************************/ -int XHdcp1x_PortWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const void *Buf, - u32 BufSize) -{ - const XHdcp1x_PortPhyIfAdaptor *Adaptor = NULL; - int NumWritten = 0; - - /* Verify arguments. */ - Xil_AssertNonvoid(InstancePtr != NULL); - Xil_AssertNonvoid(Buf != NULL); - - /* Determine Adaptor */ - Adaptor = InstancePtr->Adaptor; - - /* Invoke adaptor function if present */ - if ((Adaptor != NULL) && (Adaptor->Write != NULL)) { - NumWritten = (*(Adaptor->Write))(InstancePtr, Offset, Buf, - BufSize); - } - - return (NumWritten); -} diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port.h b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port.h index bac583e0..2faa5c04 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port.h +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port.h @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,11 +42,11 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. -* 1.01 07/23/15 Additional documentation and formating +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ + #ifndef XHDCP1X_PORT_H /**< Prevent circular inclusions by using protection macros */ #define XHDCP1X_PORT_H @@ -56,6 +56,7 @@ extern "C" { #endif /***************************** Include Files *********************************/ + #include "xhdcp1x.h" #include "xparameters.h" #include "xstatus.h" @@ -86,7 +87,8 @@ typedef struct XHdcp1x_PortPhyIfAdaptorS { int (*Write)(XHdcp1x_Port*, u8, const void*, u32); /**< Reg write */ int (*IsCapable)(const XHdcp1x_Port*); /**< Tests for HDCP capable */ int (*IsRepeater)(const XHdcp1x_Port*); /**< Tests for repeater */ - int (*GetRepeaterInfo)(const XHdcp1x_Port*, u16*); /**< Gets repeater info */ + int (*GetRepeaterInfo)(const XHdcp1x_Port*, u16*); /**< Gets repeater + info */ void (*IntrHandler)(XHdcp1x_Port *, u32); /**< Interrupt handler */ } XHdcp1x_PortPhyIfAdaptor; @@ -94,25 +96,23 @@ typedef struct XHdcp1x_PortPhyIfAdaptorS { /*****************************************************************************/ /** -* * This macro converts from an unsigned integer to a little endian formatted * buffer * -* @param buf the buffer to write to -* @param uint the unsigned integer to convert -* @param numbits the number of bits within the unsigned integer to use +* @param buf the buffer to write to +* @param uint the unsigned integer to convert +* @param numbits the number of bits within the unsigned integer to use * -* @return -* void +* @return None. * -* @note -* The value of the "uint" parameter is destroyed by a call to this macro +* @note The value of the "uint" parameter is destroyed by a call to this +* macro * ******************************************************************************/ #define XHDCP1X_PORT_UINT_TO_BUF(buf, uint, numbits) \ if ((numbits) > 0) { \ int byte; \ - for (byte=0; byte<=(((numbits)-1)>>3); byte++) { \ + for (byte = 0; byte <= (((numbits) - 1) >> 3); byte++) { \ buf[byte] = (uint8_t) (uint & 0xFFu); \ uint >>= 8; \ } \ @@ -120,26 +120,23 @@ typedef struct XHdcp1x_PortPhyIfAdaptorS { /*****************************************************************************/ /** -* * This macro converts from a little endian formatted buffer to an unsigned * integer value * -* @param uint the unsigned integer to write -* @param buf the buffer to convert -* @param numbits the number of bits within the buffer to use +* @param uint the unsigned integer to write +* @param buf the buffer to convert +* @param numbits the number of bits within the buffer to use * -* @return -* void +* @return None. * -* @note -* None. +* @note None. * ******************************************************************************/ #define XHDCP1X_PORT_BUF_TO_UINT(uint, buf, numbits) \ if ((numbits) > 0) { \ int byte; \ uint = 0; \ - for (byte=(((numbits)-1)>>3); byte>=0; byte--) { \ + for (byte = (((numbits) - 1) >> 3); byte >= 0; byte--) { \ uint <<= 8; \ uint |= buf[byte]; \ } \ @@ -147,64 +144,55 @@ typedef struct XHdcp1x_PortPhyIfAdaptorS { /*****************************************************************************/ /** -* * This macro sets a bit within a little endian formatted buffer * -* @param buf the buffer to write to -* @param bitnum the bit to set +* @param buf the buffer to write to +* @param bitnum the bit to set * -* @return -* void +* @return None. * -* @note -* None. +* @note None. * ******************************************************************************/ #define XHDCP1X_PORT_BSET_IN_BUF(buf, bitnum) \ - buf[(bitnum)>>3] |= (1u << ((bitnum) & 0x07u)); + buf[(bitnum) >> 3] |= (1u << ((bitnum) & 0x07u)); /*****************************************************************************/ /** -* * This macro clears a bit within a little endian formatted buffer * -* @param buf the buffer to write to -* @param bitnum the bit to clear +* @param buf the buffer to write to +* @param bitnum the bit to clear * -* @return -* void +* @return None. * -* @note -* None. +* @note None. * ******************************************************************************/ #define XHDCP1X_PORT_BCLR_IN_BUF(buf, bitnum) \ - buf[(bitnum)>>3] &= ~(1u << ((bitnum) & 0x07u)); + buf[(bitnum) >> 3] &= ~(1u << ((bitnum) & 0x07u)); /*****************************************************************************/ /** -* * This macro tests a bit within a little endian formatted buffer * -* @param buf the buffer containing the bit to test -* @param bitnum the bit to test +* @param buf the buffer containing the bit to test +* @param bitnum the bit to test * -* @return -* void +* @return None. * -* @note -* None. +* @note None. * ******************************************************************************/ #define XHDCP1X_PORT_BTST_IN_BUF(buf, bitnum) \ - (buf[(bitnum)>>3] & (1u << ((bitnum) & 0x07u))) + (buf[(bitnum) >> 3] & (1u << ((bitnum) & 0x07u))) /************************** Function Prototypes ******************************/ int XHdcp1x_PortCfgInitialize(XHdcp1x_Port *InstancePtr, - const XHdcp1x_Config* ConfigPtr, void *PhyIfPtr); + const XHdcp1x_Config *ConfigPtr, void *PhyIfPtr); -int XHdcp1x_PortSetCallback(XHdcp1x_Port* InstancePtr, u32 HandlerType, +int XHdcp1x_PortSetCallback(XHdcp1x_Port *InstancePtr, u32 HandlerType, XHdcp1x_Callback Callback, void *Parameter); int XHdcp1x_PortEnable(XHdcp1x_Port *InstancePtr); diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_dp.h b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_dp.h index 14a6d03b..89cd4b1f 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_dp.h +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_dp.h @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,7 +42,7 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ @@ -56,6 +56,7 @@ extern "C" { #endif /***************************** Include Files *********************************/ + #if defined(XHDCP1X_PORT_HDMI_H) #error "cannot include both xhdcp1x_port_dp.h and xhdcp1x_port_hdmi.h" #endif @@ -122,7 +123,6 @@ extern "C" { */ #define XHDCP1X_PORT_DPCD_BASE (0x68000u) /**< Base Addr in DPCD */ - /**************************** Type Definitions *******************************/ /***************** Macros (Inline Functions) Definitions *********************/ diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_dp_rx.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_dp_rx.c index 31b40fbe..26bf615a 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_dp_rx.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_dp_rx.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -29,7 +29,6 @@ * this Software without prior written authorization from Xilinx. * ******************************************************************************/ - /*****************************************************************************/ /** * @@ -43,14 +42,14 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ /***************************** Include Files *********************************/ -#include "xparameters.h" +#include "xparameters.h" #if defined(XPAR_XDP_NUM_INSTANCES) && (XPAR_XDP_NUM_INSTANCES > 0) #include #include @@ -67,348 +66,34 @@ /***************** Macros (Inline Functions) Definitions *********************/ +/*************************** Function Prototypes *****************************/ + +static int RegRead(const XHdcp1x_Port *InstancePtr, u8 Offset, u8 *Buf, + u32 BufSize); +static int RegWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const u8 *Buf, + u32 BufSize); +static void NotifyTx(const XHdcp1x_Port *InstancePtr); +static void ProcessAKsvWrite(void *CallbackRef); +static void ProcessRoRead(void *CallbackRef); +static void ProcessBinfoRead(void *CallbackRef); + /************************** Function Definitions *****************************/ /*****************************************************************************/ /** +* This function enables a HDCP port device. * -* This reads a register from the hdcp port device -* -* @param InstancePtr device to read from -* @param Offset offset to start reading from -* @param Buf buffer to copy data read -* @param BufSize size of buffer +* @param InstancePtr is the device to enable. * * @return -* number of bytes read +* - XST_SUCCESS if successful. * -* @note -* None. -* -******************************************************************************/ -static int RegRead(const XHdcp1x_Port *InstancePtr, u8 Offset, u8 *Buf, - u32 BufSize) -{ - XDprx* HwDp = InstancePtr->PhyIfPtr; - u32 Base = HwDp->Config.BaseAddr; - u32 RegOffset = 0; - int NumRead = 0; - - /* Determine RegOffset */ - RegOffset = XDP_RX_DPCD_HDCP_TABLE; - RegOffset += Offset; - - /* Iterate through the reads */ - do { - u32 Value = 0; - u32 Alignment = 0; - u32 NumThisTime = 0; - int Idx = 0; - - /* Determine Alignment */ - Alignment = (RegOffset & 0x03ul); - - /* Determine NumThisTime */ - NumThisTime = 4; - if (Alignment != 0) { - NumThisTime = (4 - Alignment); - } - if (NumThisTime > BufSize) { - NumThisTime = BufSize; - } - - /* Determine Value */ - Value = XDprx_ReadReg(Base, (RegOffset & ~0x03ul)); - - /* Check for adjustment of Value */ - if (Alignment != 0) - Value >>= (8*Alignment); - - /* Update theBuf */ - for (Idx=0; Idx>= 8; - } - - /* Update for loop */ - Buf += NumThisTime; - BufSize -= NumThisTime; - RegOffset += NumThisTime; - NumRead += NumThisTime; - } - while (BufSize > 0); - - return (NumRead); -} - -/*****************************************************************************/ -/** -* -* This writes a register from the hdcp port device -* -* @param InstancePtr device to write to -* @param Offset offset to start writing at -* @param Buf buffer containing data to write -* @param BufSize size of buffer -* -* @return -* number of bytes written -* -* @note -* None. -* -******************************************************************************/ -static int RegWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const u8 *Buf, - u32 BufSize) -{ - XDprx* HwDp = InstancePtr->PhyIfPtr; - u32 Base = HwDp->Config.BaseAddr; - u32 RegOffset = 0; - int NumWritten = 0; - - /* Determine RegOffset */ - RegOffset = XDP_RX_DPCD_HDCP_TABLE; - RegOffset += Offset; - - /* Iterate through the writes */ - do { - u32 Value = 0; - u32 Alignment = 0; - u32 NumThisTime = 0; - int Idx = 0; - - /* Determine Alignment */ - Alignment = (RegOffset & 0x03ul); - - /* Determine NumThisTime */ - NumThisTime = 4; - if (Alignment != 0) { - NumThisTime = (4 - Alignment); - } - if (NumThisTime > BufSize) { - NumThisTime = BufSize; - } - - /* Check for simple case */ - if (NumThisTime == 4) { - /* Determine Value */ - for (Idx=3; Idx>=0; Idx--) { - Value <<= 8; - Value |= Buf[Idx]; - } - } - /* Otherwise - must read and modify existing memory */ - else { - u32 Mask = 0; - u32 Temp = 0; - - /* Determine Mask */ - Mask = 0xFFu; - if (Alignment != 0) { - Mask <<= (8*Alignment); - } - - /* Initialize Value */ - Value = XDprx_ReadReg(Base, (RegOffset & ~0x03ul)); - - /* Update theValue */ - for (Idx=0; Idx 0); - - return (NumWritten); -} - -/*****************************************************************************/ -/** -* -* This function notifies the tx end of the link of an event of interest -* -* @param InstancePtr device to perform the notification -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void NotifyTx(const XHdcp1x_Port *InstancePtr) -{ - XDprx* HwDp = InstancePtr->PhyIfPtr; - u32 Base = HwDp->Config.BaseAddr; - u32 Value = 0; - u8 Ainfo = 0; - - /* Read Ainfo */ - RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_AINFO, &Ainfo, sizeof(Ainfo)); - - /* Check for regular HPD pulse notification */ - if ((Ainfo & 0x01u) == 0) { - /* Send a 500us HPD pulse */ - XDp_RxGenerateHpdInterrupt(HwDp, 500u); - } - /* Otherwise - must use HPD IRQ */ - else { - /* #### WORK TO DO #### */ - } - - /* Always generate CP IRQ */ - Value = XDprx_ReadReg(Base, XDP_RX_DEVICE_SERVICE_IRQ); - Value |= XDP_RX_DEVICE_SERVICE_IRQ_CP_IRQ_MASK; - XDprx_WriteReg(Base, XDP_RX_DEVICE_SERVICE_IRQ, Value); - - return; -} - -/*****************************************************************************/ -/** -* -* This function process a write to the AKsv register from the tx device -* -* @param CallbackRef device to whose register was written -* -* @return -* void -* -* @note -* This function initiates the side effects of the tx device writing the -* Aksv register. This is currently updates some status bits as well as -* kick starts a re-authentication process. -* -******************************************************************************/ -static void ProcessAKsvWrite(void *CallbackRef) -{ - XHdcp1x_Port *InstancePtr = CallbackRef; - u8 Value = 0; - - /* Verify arguments. */ - Xil_AssertVoid(InstancePtr != NULL); - - /* Update statistics */ - InstancePtr->Stats.IntCount++; - - /* Clear bit 0 of Ainfo register */ - RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_AINFO, &Value, 1); - Value &= 0xFEu; - RegWrite(InstancePtr, XHDCP1X_PORT_OFFSET_AINFO, &Value, 1); - - /* Clear bits 3:2 of Bstatus register */ - RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1); - Value &= 0xF3u; - RegWrite(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1); - - /* Invoke authentication callback if set */ - if (InstancePtr->IsAuthCallbackSet) { - (*(InstancePtr->AuthCallback))(InstancePtr->AuthRef); - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function process a read of the Ro' register by the tx device -* -* @param CallbackRef device to whose register was read -* -* @return -* void -* -* @note -* This function initiates the side effects of the tx device read the Ro' -* register. This is currently limited to the clearing of bits within -* device's Bstatus register. -* -******************************************************************************/ -static void ProcessRoRead(void *CallbackRef) -{ - XHdcp1x_Port *InstancePtr = CallbackRef; - u8 Value = 0; - - /* Verify arguments. */ - Xil_AssertVoid(InstancePtr != NULL); - - /* Update statistics */ - InstancePtr->Stats.IntCount++; - - /* Clear bit 1 of Bstatus register */ - RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1); - Value &= 0xFDu; - RegWrite(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1); - - return; -} - -/*****************************************************************************/ -/** -* -* This function process a read of the Binfo register by the tx device -* -* @param CallbackRef device to whose register was read -* -* @return -* void -* -* @note -* This function initiates the side effects of the tx device read the Binfo -* register. This is currently limited to the clearing of bits within -* device's Bstatus register. -* -******************************************************************************/ -static void ProcessBinfoRead(void *CallbackRef) -{ - XHdcp1x_Port *InstancePtr = CallbackRef; - u8 Value = 0; - - /* Verify arguments. */ - Xil_AssertVoid(InstancePtr != NULL); - - /* Update statistics */ - InstancePtr->Stats.IntCount++; - - /* Clear bit 0 of Bstatus register */ - RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1); - Value &= 0xFEu; - RegWrite(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1); - - return; -} - -/*****************************************************************************/ -/** -* -* This function enables a hdcp port device -* -* @param InstancePtr device to enable -* -* @return -* XST_SUCCESS if successful. -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortDpRxEnable(XHdcp1x_Port *InstancePtr) { - XDprx* HwDp = InstancePtr->PhyIfPtr; + XDprx *HwDp = InstancePtr->PhyIfPtr; u32 IntMask = 0; u8 Buf[4]; int Status = XST_SUCCESS; @@ -456,21 +141,19 @@ int XHdcp1x_PortDpRxEnable(XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** +* This function disables a HDCP port device. * -* This function disables a hdcp port device -* -* @param InstancePtr device to disable +* @param InstancePtr is the device to disable. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortDpRxDisable(XHdcp1x_Port *InstancePtr) { - XDprx* HwDp = InstancePtr->PhyIfPtr; + XDprx *HwDp = InstancePtr->PhyIfPtr; u32 IntMask = 0; u8 Offset = 0; u8 Value = 0; @@ -500,16 +183,15 @@ int XHdcp1x_PortDpRxDisable(XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** +* This function initializes a HDCP port device. * -* This function initializes a hdcp port device -* -* @param InstancePtr device to initialize +* @param InstancePtr is the device to initialize. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortDpRxInit(XHdcp1x_Port *InstancePtr) @@ -531,18 +213,16 @@ int XHdcp1x_PortDpRxInit(XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** * -* This function reads a register from a hdcp port device +* This function reads a register from a HDCP port device. * -* @param InstancePtr device to read from -* @param Offset offset to start reading from -* @param Buf buffer to copy data read -* @param BufSize size of buffer +* @param InstancePtr is the device to read from. +* @param Offset is the offset to start reading from. +* @param Buf is the buffer to copy data read. +* @param BufSize is the size of the buffer. * -* @return -* number of bytes read +* @return Is the number of bytes read. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortDpRxRead(const XHdcp1x_Port *InstancePtr, u8 Offset, @@ -563,19 +243,16 @@ int XHdcp1x_PortDpRxRead(const XHdcp1x_Port *InstancePtr, u8 Offset, /*****************************************************************************/ /** +* This function writes a register from a HDCP port device. * -* This function writes a register from a hdcp port device +* @param InstancePtr is the device to write to. +* @param Offset is the offset to start writing to. +* @param Buf is the buffer containing data to write. +* @param BufSize is the size of the buffer. * -* @param InstancePtr device to write to -* @param Offset offset to start writing to -* @param Buf buffer containing data to write -* @param BufSize size of buffer +* @return The number of bytes written. * -* @return -* number of bytes written -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortDpRxWrite(XHdcp1x_Port *InstancePtr, u8 Offset, @@ -594,47 +271,305 @@ int XHdcp1x_PortDpRxWrite(XHdcp1x_Port *InstancePtr, u8 Offset, return (RegWrite(InstancePtr, Offset, Buf, BufSize)); } -#if 0 /*****************************************************************************/ /** +* This reads a register from the HDCP port device. * -* This handles an interrupt generated by a hdcp port device +* @param InstancePtr is the device to read from. +* @param Offset is the offset to start reading from. +* @param Buf is the buffer to copy data read. +* @param BufSize is the size of the buffer. * -* @param InstancePtr the device to write to -* @param IntCause the interrupt cause bit map +* @return The number of bytes read. * -* @return -* void -* -* @note -* None. +* @note None. * ******************************************************************************/ -void XHdcp1x_PortDpRxIntrHandler(XHdcp1x_Port *InstancePtr, u32 IntCause) +static int RegRead(const XHdcp1x_Port *InstancePtr, u8 Offset, u8 *Buf, + u32 BufSize) { + XDprx *HwDp = InstancePtr->PhyIfPtr; + u32 Base = HwDp->Config.BaseAddr; + u32 RegOffset = 0; + int NumRead = 0; + + /* Determine RegOffset */ + RegOffset = XDP_RX_DPCD_HDCP_TABLE; + RegOffset += Offset; + + /* Iterate through the reads */ + do { + u32 Value = 0; + u32 Alignment = 0; + u32 NumThisTime = 0; + int Idx = 0; + + /* Determine Alignment */ + Alignment = (RegOffset & 0x03ul); + + /* Determine NumThisTime */ + NumThisTime = 4; + if (Alignment != 0) { + NumThisTime = (4 - Alignment); + } + if (NumThisTime > BufSize) { + NumThisTime = BufSize; + } + + /* Determine Value */ + Value = XDprx_ReadReg(Base, (RegOffset & ~0x03ul)); + + /* Check for adjustment of Value */ + if (Alignment != 0) + Value >>= (8 * Alignment); + + /* Update theBuf */ + for (Idx = 0; Idx < NumThisTime; Idx++) { + Buf[Idx] = (u8) (Value & 0xFFul); + Value >>= 8; + } + + /* Update for loop */ + Buf += NumThisTime; + BufSize -= NumThisTime; + RegOffset += NumThisTime; + NumRead += NumThisTime; + } + while (BufSize > 0); + + return (NumRead); +} + +/*****************************************************************************/ +/** +* This writes a register from the HDCP port device. +* +* @param InstancePtr is the device to write to. +* @param Offset is the offset to start writing at. +* @param Buf is the buffer containing data to write. +* @param BufSize is the size of the buffer. +* +* @return The number of bytes written. +* +* @note None. +* +******************************************************************************/ +static int RegWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const u8 *Buf, + u32 BufSize) +{ + XDprx *HwDp = InstancePtr->PhyIfPtr; + u32 Base = HwDp->Config.BaseAddr; + u32 RegOffset = 0; + int NumWritten = 0; + + /* Determine RegOffset */ + RegOffset = XDP_RX_DPCD_HDCP_TABLE; + RegOffset += Offset; + + /* Iterate through the writes */ + do { + u32 Value = 0; + u32 Alignment = 0; + u32 NumThisTime = 0; + int Idx = 0; + + /* Determine Alignment */ + Alignment = (RegOffset & 0x03ul); + + /* Determine NumThisTime */ + NumThisTime = 4; + if (Alignment != 0) { + NumThisTime = (4 - Alignment); + } + if (NumThisTime > BufSize) { + NumThisTime = BufSize; + } + + /* Check for simple case */ + if (NumThisTime == 4) { + /* Determine Value */ + for (Idx = 3; Idx >= 0; Idx--) { + Value <<= 8; + Value |= Buf[Idx]; + } + } + /* Otherwise - must read and modify existing memory */ + else { + u32 Mask = 0; + u32 Temp = 0; + + /* Determine Mask */ + Mask = 0xFFu; + if (Alignment != 0) { + Mask <<= (8 * Alignment); + } + + /* Initialize Value */ + Value = XDprx_ReadReg(Base, (RegOffset & ~0x03ul)); + + /* Update theValue */ + for (Idx = 0; Idx < NumThisTime; Idx++) { + Temp = Buf[Idx]; + Temp <<= (8 * (Alignment + Idx)); + Value &= ~Mask; + Value |= Temp; + Mask <<= 8; + } + } + + /* Write Value */ + XDprx_WriteReg(Base, (RegOffset & ~0x03ul), Value); + + /* Update for loop */ + Buf += NumThisTime; + BufSize -= NumThisTime; + RegOffset += NumThisTime; + NumWritten += NumThisTime; + } + while (BufSize > 0); + + return (NumWritten); +} + +/*****************************************************************************/ +/** +* This function notifies the tx end of the link of an event of interest. +* +* @param InstancePtr is the device to perform the notification. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void NotifyTx(const XHdcp1x_Port *InstancePtr) +{ + XDprx *HwDp = InstancePtr->PhyIfPtr; + u32 Base = HwDp->Config.BaseAddr; + u32 Value = 0; + u8 Ainfo = 0; + + /* Read Ainfo */ + RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_AINFO, &Ainfo, sizeof(Ainfo)); + + /* Check for regular HPD pulse notification */ + if ((Ainfo & 0x01u) == 0) { + /* Send a 500us HPD pulse */ + XDp_RxGenerateHpdInterrupt(HwDp, 500u); + } + /* Otherwise - must use HPD IRQ */ + else { + /* #### WORK TO DO #### */ + } + + /* Always generate CP IRQ */ + Value = XDprx_ReadReg(Base, XDP_RX_DEVICE_SERVICE_IRQ); + Value |= XDP_RX_DEVICE_SERVICE_IRQ_CP_IRQ_MASK; + XDprx_WriteReg(Base, XDP_RX_DEVICE_SERVICE_IRQ, Value); +} + +/*****************************************************************************/ +/** +* This function process a write to the AKsv register from the tx device. +* +* @param CallbackRef is the device to whose register was written. +* +* @return None. +* +* @note This function initiates the side effects of the tx device +* writing the Aksv register. This is currently updates some status +* bits as well as kick starts a re-authentication process. +* +******************************************************************************/ +static void ProcessAKsvWrite(void *CallbackRef) +{ + XHdcp1x_Port *InstancePtr = CallbackRef; + u8 Value = 0; + /* Verify arguments. */ Xil_AssertVoid(InstancePtr != NULL); - /* Check for AKsv write */ - if (IntCause & XDP_RX_INTERRUPT_MASK_HDCP_AKSV_WRITE_MASK) { - ProcessAKsvWrite(InstancePtr); - } - /* Check for Ro read */ - if (IntCause & XDP_RX_INTERRUPT_MASK_HDCP_RO_READ_MASK) { - ProcessRoRead(InstancePtr); - } - /* Check for Binfo read */ - if (IntCause & XDP_RX_INTERRUPT_MASK_HDCP_BINFO_READ_MASK) { - ProcessBinfoRead(InstancePtr); - } + /* Update statistics */ + InstancePtr->Stats.IntCount++; - return; + /* Clear bit 0 of Ainfo register */ + RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_AINFO, &Value, 1); + Value &= 0xFEu; + RegWrite(InstancePtr, XHDCP1X_PORT_OFFSET_AINFO, &Value, 1); + + /* Clear bits 3:2 of Bstatus register */ + RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1); + Value &= 0xF3u; + RegWrite(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1); + + /* Invoke authentication callback if set */ + if (InstancePtr->IsAuthCallbackSet) { + (*(InstancePtr->AuthCallback))(InstancePtr->AuthRef); + } } -#endif /*****************************************************************************/ /** +* This function process a read of the Ro' register by the tx device. * +* @param CallbackRef is the device to whose register was read. +* +* @return None. +* +* @note This function initiates the side effects of the tx device read +* the Ro' register. This is currently limited to the clearing of +* bits within device's Bstatus register. +* +******************************************************************************/ +static void ProcessRoRead(void *CallbackRef) +{ + XHdcp1x_Port *InstancePtr = CallbackRef; + u8 Value = 0; + + /* Verify arguments. */ + Xil_AssertVoid(InstancePtr != NULL); + + /* Update statistics */ + InstancePtr->Stats.IntCount++; + + /* Clear bit 1 of Bstatus register */ + RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1); + Value &= 0xFDu; + RegWrite(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1); +} + +/*****************************************************************************/ +/** +* This function process a read of the Binfo register by the tx device. +* +* @param CallbackRef is the device to whose register was read. +* +* @return None. +* +* @note This function initiates the side effects of the tx device read +* the Binfo register. This is currently limited to the clearing of +* bits within device's Bstatus register. +* +******************************************************************************/ +static void ProcessBinfoRead(void *CallbackRef) +{ + XHdcp1x_Port *InstancePtr = CallbackRef; + u8 Value = 0; + + /* Verify arguments. */ + Xil_AssertVoid(InstancePtr != NULL); + + /* Update statistics */ + InstancePtr->Stats.IntCount++; + + /* Clear bit 0 of Bstatus register */ + RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1); + Value &= 0xFEu; + RegWrite(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1); +} + +/*****************************************************************************/ +/** * This tables defines adaptor for DP RX HDCP port driver * ******************************************************************************/ @@ -649,7 +584,7 @@ const XHdcp1x_PortPhyIfAdaptor XHdcp1x_PortDpRxAdaptor = NULL, NULL, NULL, -// &XHdcp1x_PortDpRxIntrHandler, }; -#endif /* defined(XPAR_XDP_RX_NUM_INSTANCES) && (XPAR_XDP_RX_NUM_INSTANCES > 0) */ +#endif +/* defined(XPAR_XDP_RX_NUM_INSTANCES) && (XPAR_XDP_RX_NUM_INSTANCES > 0) */ diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_dp_tx.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_dp_tx.c index 4c99bc3f..cffec539 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_dp_tx.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_dp_tx.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,15 +42,14 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. -* 1.01 07/23/15 Fixed link verification handling +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ /***************************** Include Files *********************************/ -#include "xparameters.h" +#include "xparameters.h" #if defined(XPAR_XDP_NUM_INSTANCES) && (XPAR_XDP_NUM_INSTANCES > 0) #include "xhdcp1x_port.h" #include "xhdcp1x_port_dp.h" @@ -65,135 +64,27 @@ /***************** Macros (Inline Functions) Definitions *********************/ +/*************************** Function Prototypes *****************************/ + +static int RegRead(const XHdcp1x_Port *InstancePtr, u8 Offset, u8 *Buf, + u32 BufSize); +static int RegWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const u8 *Buf, + u32 BufSize); +static void CheckForRxStatusChange(XHdcp1x_Port *InstancePtr); + /************************** Function Definitions *****************************/ /*****************************************************************************/ /** +* This function enables a HDCP port device. * -* This reads a register from the hdcp port device -* -* @param InstancePtr the device to read from -* @param Offset the offset to start reading from -* @param Buf the buffer to copy the data read -* @param BufSize the size of the buffer +* @param InstancePtr is the id of the device to enable. * * @return -* The number of bytes read +* - XST_SUCCESS if successful. +* - XST_NOT_ENABLE otherwise. * -* @note -* None. -* -******************************************************************************/ -static int RegRead(const XHdcp1x_Port *InstancePtr, u8 Offset, u8 *Buf, - u32 BufSize) -{ - /* Locals */ - XDptx* DpHw = InstancePtr->PhyIfPtr; - u32 Address = 0; - int NumRead = 0; - - /* Determine Address */ - Address = Offset; - Address += 0x68000u; - - /* Read it */ - if (XDp_TxAuxRead(DpHw, Address, BufSize, Buf) == XST_SUCCESS) { - NumRead = BufSize; - } - - /* Return */ - return (NumRead); -} - -/*****************************************************************************/ -/** -* -* This writes a register from the hdcp port device -* -* @param InstancePtr the device to write to -* @param Offset the offset to start writing at -* @param Buf the buffer containing the data to write -* @param BufSize the size of the buffer -* -* @return -* The number of bytes written -* -* @note -* None. -* -******************************************************************************/ -static int RegWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const u8 *Buf, - u32 BufSize) -{ - /* Locals */ - XDptx* DpHw = InstancePtr->PhyIfPtr; - u32 Address = 0; - int NumWritten = 0; - - /* Determine Address */ - Address = Offset; - Address += 0x68000u; - - /* Write it */ - if (XDp_TxAuxWrite(DpHw, Address, BufSize, (u8*) Buf) == XST_SUCCESS) { - NumWritten = BufSize; - } - - /* Return */ - return (NumWritten); -} - -/*****************************************************************************/ -/** -* -* This function checks for a link integrity check failure or re-auth request -* -* @param InstancePtr the device to process the failure -* -* @return -* void -* -* @note -* None -* -******************************************************************************/ -static void CheckForRxStatusChange(XHdcp1x_Port *InstancePtr) -{ - u8 Value = 0; - - /* Read the Bstatus register */ - if (RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1) > 0) { - u8 ReauthMask = 0; - - /* Determine ReauthMask */ - ReauthMask = XHDCP1X_PORT_BIT_BSTATUS_LINK_FAILURE; - ReauthMask |= XHDCP1X_PORT_BIT_BSTATUS_REAUTH_REQUEST; - - /* Check for link failure or re-authentication requested */ - if ((Value & ReauthMask) != 0) { - /* Invoke authentication callback if set */ - if (InstancePtr->IsAuthCallbackSet) { - (*(InstancePtr->AuthCallback))( - InstancePtr->AuthRef); - } - } - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function enables a hdcp port device -* -* @param InstancePtr the id of the device to enable -* -* @return -* XST_SUCCESS if successful. -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortDpTxEnable(XHdcp1x_Port *InstancePtr) @@ -215,16 +106,14 @@ int XHdcp1x_PortDpTxEnable(XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** +* This function disables a HDCP port device. * -* This function disables a hdcp port device -* -* @param InstancePtr the id of the device to disable +* @param InstancePtr is the id of the device to disable. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortDpTxDisable(XHdcp1x_Port *InstancePtr) @@ -241,16 +130,15 @@ int XHdcp1x_PortDpTxDisable(XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** +* This function initializes a HDCP port device. * -* This function initializes a hdcp port device -* -* @param InstancePtr the device to initialize +* @param InstancePtr is the device to initialize. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortDpTxInit(XHdcp1x_Port *InstancePtr) @@ -264,7 +152,7 @@ int XHdcp1x_PortDpTxInit(XHdcp1x_Port *InstancePtr) Xil_AssertNonvoid(InstancePtr->PhyIfPtr != NULL); /* Ensure that the dp video path routes through the hdcp core */ - Base = ((XDptx*) InstancePtr->PhyIfPtr)->Config.BaseAddr; + Base = ((XDptx *)InstancePtr->PhyIfPtr)->Config.BaseAddr; Value = XDptx_ReadReg(Base, XDP_TX_HDCP_ENABLE); Value |= XDP_TX_HDCP_ENABLE_BYPASS_DISABLE_MASK; XDptx_WriteReg(Base, XDP_TX_HDCP_ENABLE, Value); @@ -279,16 +167,13 @@ int XHdcp1x_PortDpTxInit(XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** +* This function confirms the presence/capability of the remote HDCP device. * -* This function confirms the presence/capability of the remote hdcp device +* @param InstancePtr is the device to query. * -* @param InstancePtr the device to query +* @return Truth value. * -* @return -* Truth value -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortDpTxIsCapable(const XHdcp1x_Port *InstancePtr) @@ -312,15 +197,13 @@ int XHdcp1x_PortDpTxIsCapable(const XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** * -* This function confirms if the remote hdcp device is a repeater +* This function confirms if the remote HDCP device is a repeater. * -* @param InstancePtr the device to query +* @param InstancePtr is the device to query. * -* @return -* Truth value +* @return Truth value. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortDpTxIsRepeater(const XHdcp1x_Port *InstancePtr) @@ -343,16 +226,17 @@ int XHdcp1x_PortDpTxIsRepeater(const XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** +* This function retrieves the repeater information. * -* This function retrieves the repeater information -* -* @param InstancePtr the device to query +* @param InstancePtr is the device to query. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_DEVICE_BUSY if the device is busy. +* - XST_NO_FEATURE if feature not part of repeater. +* - XST_RECV_ERROR if receiver read failed. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortDpTxGetRepeaterInfo(const XHdcp1x_Port *InstancePtr, u16 *Info) @@ -366,17 +250,14 @@ int XHdcp1x_PortDpTxGetRepeaterInfo(const XHdcp1x_Port *InstancePtr, u16 *Info) /* Read the remote capabilities */ if (RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_BCAPS, &Value, 1) > 0) { - /* Check for repeater */ if ((Value & XHDCP1X_PORT_BIT_BCAPS_REPEATER) != 0) { - /* Read the remote status */ RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1); /* Check for ready */ if ((Value & XHDCP1X_PORT_BIT_BSTATUS_READY) != 0) { - u8 Buf[2]; u16 U16Value = 0; @@ -389,7 +270,6 @@ int XHdcp1x_PortDpTxGetRepeaterInfo(const XHdcp1x_Port *InstancePtr, u16 *Info) /* Update Info */ *Info = (U16Value & 0x0FFFu); - } else { Status = XST_DEVICE_BUSY; @@ -408,19 +288,16 @@ int XHdcp1x_PortDpTxGetRepeaterInfo(const XHdcp1x_Port *InstancePtr, u16 *Info) /*****************************************************************************/ /** +* This function reads a register from a HDCP port device. * -* This function reads a register from a hdcp port device +* @param InstancePtr is the device to read from. +* @param Offset is the offset to start reading from. +* @param Buf is the buffer to copy the data read. +* @param BufSize is the size of the buffer. * -* @param InstancePtr the device to read from -* @param Offset the offset to start reading from -* @param Buf the buffer to copy the data read -* @param BufSize the size of the buffer +* @return The number of bytes read. * -* @return -* The number of bytes read -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortDpTxRead(const XHdcp1x_Port *InstancePtr, u8 Offset, @@ -441,19 +318,16 @@ int XHdcp1x_PortDpTxRead(const XHdcp1x_Port *InstancePtr, u8 Offset, /*****************************************************************************/ /** +* This function writes a register from a HDCP port device. * -* This function writes a register from a hdcp port device +* @param InstancePtr is the device to write to. +* @param Offset is the offset to start writing to. +* @param Buf is the buffer containing the data to write. +* @param BufSize is the size of the buffer. * -* @param InstancePtr the device to write to -* @param Offset the offset to start writing to -* @param Buf the buffer containing the data to write -* @param BufSize the size of the buffer +* @return The number of bytes written. * -* @return -* The number of bytes written -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortDpTxWrite(XHdcp1x_Port *InstancePtr, u8 Offset, @@ -474,17 +348,14 @@ int XHdcp1x_PortDpTxWrite(XHdcp1x_Port *InstancePtr, u8 Offset, /*****************************************************************************/ /** +* This handles an interrupt generated by a HDCP port device. * -* This handles an interrupt generated by a hdcp port device +* @param InstancePtr is the device to write to. +* @param IntCause is the interrupt cause bit map. * -* @param InstancePtr the device to write to -* @param IntCause the interrupt cause bit map +* @return None. * -* @return -* void -* -* @note -* None. +* @note None. * ******************************************************************************/ void XHdcp1x_PortDpTxIntrHandler(XHdcp1x_Port *InstancePtr, u32 IntCause) @@ -506,13 +377,110 @@ void XHdcp1x_PortDpTxIntrHandler(XHdcp1x_Port *InstancePtr, u32 IntCause) if (HpdDetected) { CheckForRxStatusChange(InstancePtr); } - - return; } /*****************************************************************************/ /** +* This reads a register from the HDCP port device. * +* @param InstancePtr is the device to read from. +* @param Offset is the offset to start reading from. +* @param Buf is the buffer to copy the data read. +* @param BufSize is the size of the buffer. +* +* @return The number of bytes read. +* +* @note None. +* +******************************************************************************/ +static int RegRead(const XHdcp1x_Port *InstancePtr, u8 Offset, u8 *Buf, + u32 BufSize) +{ + XDptx *DpHw = InstancePtr->PhyIfPtr; + u32 Address = 0; + int NumRead = 0; + + /* Determine Address */ + Address = Offset; + Address += 0x68000u; + + /* Read it */ + if (XDp_TxAuxRead(DpHw, Address, BufSize, Buf) == XST_SUCCESS) { + NumRead = BufSize; + } + + return (NumRead); +} + +/*****************************************************************************/ +/** +* This writes a register from the HDCP port device. +* +* @param InstancePtr is the device to write to. +* @param Offset is the offset to start writing at. +* @param Buf is the buffer containing the data to write. +* @param BufSize is the size of the buffer. +* +* @return The number of bytes written. +* +* @note None. +* +******************************************************************************/ +static int RegWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const u8 *Buf, + u32 BufSize) +{ + XDptx *DpHw = InstancePtr->PhyIfPtr; + u32 Address = 0; + int NumWritten = 0; + + /* Determine Address */ + Address = Offset; + Address += 0x68000u; + + /* Write it */ + if (XDp_TxAuxWrite(DpHw, Address, BufSize, (u8 *)Buf) == XST_SUCCESS) { + NumWritten = BufSize; + } + + return (NumWritten); +} + +/*****************************************************************************/ +/** +* This function checks for a link integrity check failure or re-auth request. +* +* @param InstancePtr is the device to process the failure. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void CheckForRxStatusChange(XHdcp1x_Port *InstancePtr) +{ + u8 Value = 0; + + /* Read the Bstatus register */ + if (RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_BSTATUS, &Value, 1) > 0) { + u8 ReauthMask = 0; + + /* Determine ReauthMask */ + ReauthMask = XHDCP1X_PORT_BIT_BSTATUS_LINK_FAILURE; + ReauthMask |= XHDCP1X_PORT_BIT_BSTATUS_REAUTH_REQUEST; + + /* Check for link failure or re-authentication requested */ + if ((Value & ReauthMask) != 0) { + /* Invoke authentication callback if set */ + if (InstancePtr->IsAuthCallbackSet) { + (*(InstancePtr->AuthCallback))( + InstancePtr->AuthRef); + } + } + } +} + +/*****************************************************************************/ +/** * This tables defines the adaptor for the DP TX HDCP port driver * ******************************************************************************/ @@ -529,4 +497,5 @@ const XHdcp1x_PortPhyIfAdaptor XHdcp1x_PortDpTxAdaptor = &XHdcp1x_PortDpTxIntrHandler, }; -#endif /* defined(XPAR_XDP_TX_NUM_INSTANCES) && (XPAR_XDP_TX_NUM_INSTANCES > 0) */ +#endif +/* defined(XPAR_XDP_TX_NUM_INSTANCES) && (XPAR_XDP_TX_NUM_INSTANCES > 0) */ diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_hdmi.h b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_hdmi.h index f80d4606..4488ccc9 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_hdmi.h +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_hdmi.h @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,7 +42,7 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ @@ -130,7 +130,6 @@ extern "C" { /************************** Function Prototypes ******************************/ - #ifdef __cplusplus } #endif diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_hdmi_rx.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_hdmi_rx.c index 482600ea..428fc995 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_hdmi_rx.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_hdmi_rx.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,14 +42,14 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ /***************************** Include Files *********************************/ -#include "xparameters.h" +#include "xparameters.h" #if defined(XPAR_XHDMI_RX_NUM_INSTANCES) && (XPAR_XHDMI_RX_NUM_INSTANCES > 0) #include #include @@ -65,128 +65,26 @@ /***************** Macros (Inline Functions) Definitions *********************/ +/*************************** Function Prototypes *****************************/ + +static int RegRead(const XHdcp1x_Port *InstancePtr, u8 Offset, u8 *Buf, + u32 BufSize); +static int RegWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const u8 *Buf, + u32 BufSize); +static void ProcessAKsvWrite(void *CallbackRef); + /************************** Function Definitions *****************************/ /*****************************************************************************/ /** +* This function enables a HDCP port device. * -* This reads a register from the hdcp port device -* -* @param InstancePtr the device to read from -* @param Offset the offset to start reading from -* @param Buf the Bufer to copy the data read -* @param BufSize the size of the Bufer +* @param InstancePtr is the id of the device to enable. * * @return -* The number of bytes read +* - XST_SUCCESS if successful. * -* @note -* None. -* -******************************************************************************/ -static int RegRead(const XHdcp1x_Port *InstancePtr, u8 Offset, u8 *Buf, - u32 BufSize) -{ - /* Locals */ - XHdmi_Rx *HdmiRx = InstancePtr->PhyIfPtr; - u32 NumLeft = BufSize; - - /* Write the offset */ - XHdmiRx_DdcHdcpSetAddress(HdmiRx, Offset); - - /* Read the buffer */ - while (NumLeft-- > 0) { - *Buf++ = XHdmiRx_DdcHdcpReadData(HdmiRx); - } - - /* Return */ - return ((int) BufSize); -} - -/*****************************************************************************/ -/** -* -* This writes a register from the hdcp port device -* -* @param InstancePtr the device to write to -* @param Offset the offset to start writing at -* @param Buf the Bufer containing the data to write -* @param BufSize the size of the Bufer -* -* @return -* The number of bytes written -* -* @note -* None. -* -******************************************************************************/ -static int RegWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const u8 *Buf, - u32 BufSize) -{ - XHdmi_Rx *HdmiRx = InstancePtr->PhyIfPtr; - u32 NumLeft = BufSize; - - /* Write the offset */ - XHdmiRx_DdcHdcpSetAddress(HdmiRx, Offset); - - /* Write the buffer */ - while (NumLeft-- > 0) { - XHdmiRx_DdcHdcpWriteData(HdmiRx, *Buf++); - } - - /* Return */ - return ((int) BufSize); -} - -/*****************************************************************************/ -/** -* -* This function process a write to the AKsv register from the tx device -* -* @param CallbackRef the device to whose register was written -* -* @return -* void -* -* @note -* This function initiates the side effects of the tx device writing the Aksv -* register. This is currently updates some status bits as well as kick -* starts a re-authentication process. -* -******************************************************************************/ -static void ProcessAKsvWrite(void *CallbackRef) -{ - XHdcp1x_Port *InstancePtr = (XHdcp1x_Port *) CallbackRef; - u8 Value = 0; - - /* Update statistics */ - InstancePtr->Stats.IntCount++; - - /* Clear bit 1 of the Ainfo register */ - RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_AINFO, &Value, 1); - Value &= 0xFDu; - RegWrite(InstancePtr, XHDCP1X_PORT_OFFSET_AINFO, &Value, 1); - - /* Invoke authentication callback if set */ - if (InstancePtr->IsAuthCallbackSet) { - (*(InstancePtr->AuthCallback))(InstancePtr->AuthRef); - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function enables a hdcp port device -* -* @param InstancePtr the id of the device to enable -* -* @return -* XST_SUCCESS if successful. -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortHdmiRxEnable(XHdcp1x_Port *InstancePtr) @@ -233,16 +131,14 @@ int XHdcp1x_PortHdmiRxEnable(XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** +* This function disables a HDCP port device. * -* This function disables a hdcp port device -* -* @param InstancePtr the id of the device to disable +* @param InstancePtr is the id of the device to disable. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortHdmiRxDisable(XHdcp1x_Port *InstancePtr) @@ -259,7 +155,7 @@ int XHdcp1x_PortHdmiRxDisable(XHdcp1x_Port *InstancePtr) Xil_AssertNonvoid(InstancePtr->PhyIfPtr != NULL); /* Determine HdmiRxBase */ - HdmiRxBase = ((XHdmi_Rx*) InstancePtr->PhyIfPtr)->Config.BaseAddress; + HdmiRxBase = ((XHdmi_Rx *)InstancePtr->PhyIfPtr)->Config.BaseAddress; /* Disable the hdcp ddc slave */ Value = XHdmiRx_ReadReg(HdmiRxBase, XHDMI_RX_DDC_CTRL_SET_OFFSET); @@ -279,16 +175,15 @@ int XHdcp1x_PortHdmiRxDisable(XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** +* This function initializes a HDCP port device. * -* This function initializes a hdcp port device -* -* @param InstancePtr the device to initialize +* @param InstancePtr is the device to initialize. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortHdmiRxInit(XHdcp1x_Port *InstancePtr) @@ -310,18 +205,16 @@ int XHdcp1x_PortHdmiRxInit(XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** * -* This function reads a register from a hdcp port device +* This function reads a register from a HDCP port device. * -* @param InstancePtr the device to read from -* @param Offset the offset to start reading from -* @param Buf the Bufer to copy the data read -* @param BufSize the size of the Bufer +* @param InstancePtr is the device to read from. +* @param Offset is the offset to start reading from. +* @param Buf is the buffer to copy the data read. +* @param BufSize is the size of the buffer. * -* @return -* The number of bytes read +* @return The number of bytes read. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortHdmiRxRead(const XHdcp1x_Port *InstancePtr, u8 Offset, @@ -342,19 +235,16 @@ int XHdcp1x_PortHdmiRxRead(const XHdcp1x_Port *InstancePtr, u8 Offset, /*****************************************************************************/ /** +* This function writes a register from a HDCP port device. * -* This function writes a register from a hdcp port device +* @param InstancePtr is the device to write to. +* @param Offset is the offset to start writing to. +* @param Buf is the buffer containing the data to write. +* @param BufSize is the size of the buffer. * -* @param InstancePtr the device to write to -* @param Offset the offset to start writing to -* @param Buf the Bufer containing the data to write -* @param BufSize the size of the Bufer +* @return The number of bytes written. * -* @return -* The number of bytes written -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortHdmiRxWrite(XHdcp1x_Port *InstancePtr, u8 Offset, @@ -373,37 +263,102 @@ int XHdcp1x_PortHdmiRxWrite(XHdcp1x_Port *InstancePtr, u8 Offset, return (RegWrite(InstancePtr, Offset, Buf, BufSize)); } -#if 0 /*****************************************************************************/ /** +* This reads a register from the HDCP port device. * -* This function serves as the interrupt handler for the hdcp port device +* @param InstancePtr is the device to read from. +* @param Offset is the offset to start reading from. +* @param Buf is the buffer to copy the data read. +* @param BufSize is the size of the buffer. * -* @param CallbackRef the device that generated the interrupt +* @return The number of bytes read. * -* @return -* void -* -* @note -* None. +* @note None. * ******************************************************************************/ -void XHdcp1x_PortHdmiRxIntrHandler(XHdcp1x_Port *InstancePtr, u32 IntCause) +static int RegRead(const XHdcp1x_Port *InstancePtr, u8 Offset, u8 *Buf, + u32 BufSize) { - /* Verify arguments. */ - Xil_AssertVoid(InstancePtr != NULL); + XHdmi_Rx *HdmiRx = InstancePtr->PhyIfPtr; + u32 NumLeft = BufSize; - /* Process the Aksv write as it is the only hdcp interrupt */ - ProcessAKsvWrite(InstancePtr); + /* Write the offset */ + XHdmiRx_DdcHdcpSetAddress(HdmiRx, Offset); - /* Return */ - return; + /* Read the buffer */ + while (NumLeft-- > 0) { + *Buf++ = XHdmiRx_DdcHdcpReadData(HdmiRx); + } + + return ((int) BufSize); } -#endif /*****************************************************************************/ /** +* This writes a register from the HDCP port device. * +* @param InstancePtr is the device to write to. +* @param Offset is the offset to start writing at. +* @param Buf is the buffer containing the data to write. +* @param BufSize is the size of the buffer. +* +* @return The number of bytes written. +* +* @note None. +* +******************************************************************************/ +static int RegWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const u8 *Buf, + u32 BufSize) +{ + XHdmi_Rx *HdmiRx = InstancePtr->PhyIfPtr; + u32 NumLeft = BufSize; + + /* Write the offset */ + XHdmiRx_DdcHdcpSetAddress(HdmiRx, Offset); + + /* Write the buffer */ + while (NumLeft-- > 0) { + XHdmiRx_DdcHdcpWriteData(HdmiRx, *Buf++); + } + + return ((int) BufSize); +} + +/*****************************************************************************/ +/** +* This function process a write to the AKsv register from the tx device. +* +* @param CallbackRef is the device to whose register was written. +* +* @return None. +* +* @note This function initiates the side effects of the tx device +* writing the Aksv register. This is currently updates some status +* bits as well as kick starts a re-authentication process. +* +******************************************************************************/ +static void ProcessAKsvWrite(void *CallbackRef) +{ + XHdcp1x_Port *InstancePtr = (XHdcp1x_Port *) CallbackRef; + u8 Value = 0; + + /* Update statistics */ + InstancePtr->Stats.IntCount++; + + /* Clear bit 1 of the Ainfo register */ + RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_AINFO, &Value, 1); + Value &= 0xFDu; + RegWrite(InstancePtr, XHDCP1X_PORT_OFFSET_AINFO, &Value, 1); + + /* Invoke authentication callback if set */ + if (InstancePtr->IsAuthCallbackSet) { + (*(InstancePtr->AuthCallback))(InstancePtr->AuthRef); + } +} + +/*****************************************************************************/ +/** * This tables defines the adaptor for the HDMI RX HDCP port driver * ******************************************************************************/ @@ -418,7 +373,7 @@ const XHdcp1x_PortPhyIfAdaptor XHdcp1x_PortHdmiRxAdaptor = NULL, NULL, NULL, -// &XHdcp1x_PortHdmiRxIntrHandler, }; -#endif /* defined(XPAR_XHDMI_RX_NUM_INSTANCES) && (XPAR_XHDMI_RX_NUM_INSTANCES > 0) */ +#endif +/* defined(XPAR_XHDMI_RX_NUM_INSTANCES) && (XPAR_XHDMI_RX_NUM_INSTANCES > 0) */ diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_hdmi_tx.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_hdmi_tx.c index 468d08af..2eb8ae60 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_hdmi_tx.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_hdmi_tx.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,14 +42,14 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ /***************************** Include Files *********************************/ -#include "xparameters.h" +#include "xparameters.h" #if defined(XPAR_XHDMI_TX_NUM_INSTANCES) && (XPAR_XHDMI_TX_NUM_INSTANCES > 0) #include #include @@ -60,125 +60,32 @@ #include "xil_types.h" /************************** Constant Definitions *****************************/ + #define WRITE_CHUNK_SZ (8) /**************************** Type Definitions *******************************/ /***************** Macros (Inline Functions) Definitions *********************/ +/*************************** Function Prototypes *****************************/ + +static int RegRead(const XHdcp1x_Port *InstancePtr, u8 Offset, u8 *Buf, + u32 BufSize); +static int RegWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const u8 *Buf, + u32 BufSize); + /************************** Function Definitions *****************************/ /*****************************************************************************/ /** +* This function enables a HDCP port device. * -* This reads a register from the hdcp port device -* -* @param InstancePtr the device to read from -* @param Offdry the offset to start reading from -* @param Buf the buffer to copy the data read -* @param BufSize the size of the buffer +* @param InstancePtr is the id of the device to enable. * * @return -* The number of bytes read +* - XST_SUCCESS if successful. * -* @note -* None. -* -******************************************************************************/ -static int RegRead(const XHdcp1x_Port *InstancePtr, u8 Offset, u8 *Buf, - u32 BufSize) -{ - XHdmi_Tx* HdmiTx = InstancePtr->PhyIfPtr; - u8 Slave = 0x3Au; - int NumRead = 0; - - /* Write the address and check for failure */ - if (XHdmiTx_DdcWrite(HdmiTx, Slave, 1, &Offset, FALSE) - != XST_SUCCESS) { - NumRead = -1; - } - /* Read the data back and check for failure */ - else if (XHdmiTx_DdcRead(HdmiTx, Slave, BufSize, Buf, TRUE) - != XST_SUCCESS) { - NumRead = -2; - } - /* Success - just update NumRead */ - else { - NumRead = (int) BufSize; - } - - return (NumRead); -} - -/*****************************************************************************/ -/** -* -* This writes a register from the hdcp port device -* -* @param InstancePtr the device to write to -* @param Offset the offset to start writing at -* @param Buf the buffer containing the data to write -* @param BufSize the size of the buffer -* -* @return -* The number of bytes written -* -* @note -* None. -* -******************************************************************************/ -static int RegWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const u8 *Buf, - u32 BufSize) -{ - XHdmi_Tx* HdmiTx = InstancePtr->PhyIfPtr; - u8 Slave = 0x3Au; - u8 TxBuf[WRITE_CHUNK_SZ+1]; - int NumWritten = 0; - int ThisTime = 0; - - /* Iterate through the buffer */ - do { - /* Determine ThisTime */ - ThisTime = WRITE_CHUNK_SZ; - if (ThisTime > BufSize) { - ThisTime = BufSize; - } - - /* Format TxBuf */ - TxBuf[0] = Offset; - memcpy(&(TxBuf[1]), Buf, ThisTime); - - /* Write the TxBuf */ - if (XHdmiTx_DdcWrite(HdmiTx, Slave, (ThisTime+1), TxBuf, TRUE) - != XST_SUCCESS) { - /* Update NumWritten and break */ - NumWritten = -1; - break; - } - - /* Update for loop */ - NumWritten += ThisTime; - Buf += ThisTime; - BufSize -= ThisTime; - - } while ((BufSize != 0) && (NumWritten > 0)); - - /* Return */ - return (NumWritten); -} - -/*****************************************************************************/ -/** -* -* This function enables a hdcp port device -* -* @param InstancePtr the id of the device to enable -* -* @return -* XST_SUCCESS if successful. -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortHdmiTxEnable(XHdcp1x_Port *InstancePtr) @@ -200,16 +107,14 @@ int XHdcp1x_PortHdmiTxEnable(XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** +* This function disables a HDCP port device. * -* This function disables a hdcp port device -* -* @param InstancePtr the id of the device to disable +* @param InstancePtr is the id of the device to disable. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortHdmiTxDisable(XHdcp1x_Port *InstancePtr) @@ -226,16 +131,15 @@ int XHdcp1x_PortHdmiTxDisable(XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** +* This function initializes an HDCP port device. * -* This function initializes a hdcp port device -* -* @param InstancePtr the device to initialize +* @param InstancePtr is the device to initialize. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortHdmiTxInit(XHdcp1x_Port *InstancePtr) @@ -256,16 +160,13 @@ int XHdcp1x_PortHdmiTxInit(XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** +* This function confirms the presence/capability of the remote HDCP device. * -* This function confirms the presence/capability of the remote hdcp device +* @param InstancePtr is the device to query. * -* @param InstancePtr the device to query +* @return Truth value. * -* @return -* Truth value -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortHdmiTxIsCapable(const XHdcp1x_Port *InstancePtr) @@ -288,16 +189,13 @@ int XHdcp1x_PortHdmiTxIsCapable(const XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** +* This function confirms if the remote HDCP device is a repeater. * -* This function confirms if the remote hdcp device is a repeater +* @param InstancePtr is the device to query. * -* @param InstancePtr the device to query +* @return Truth value. * -* @return -* Truth value -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortHdmiTxIsRepeater(const XHdcp1x_Port *InstancePtr) @@ -320,16 +218,16 @@ int XHdcp1x_PortHdmiTxIsRepeater(const XHdcp1x_Port *InstancePtr) /*****************************************************************************/ /** +* This function retrieves the repeater information. * -* This function retrieves the repeater information -* -* @param InstancePtr the device to query +* @param InstancePtr is the device to query. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. +* - XST_DEVICE_BUSY if the device is busy. +* - XST_RECV_ERROR if receiver read failed. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortHdmiTxGetRepeaterInfo(const XHdcp1x_Port *InstancePtr, u16 *Info) @@ -343,7 +241,6 @@ int XHdcp1x_PortHdmiTxGetRepeaterInfo(const XHdcp1x_Port *InstancePtr, u16 *Info /* Read the remote capabilities */ if (RegRead(InstancePtr, XHDCP1X_PORT_OFFSET_BCAPS, &Value, 1) > 0) { - u8 ReadyMask = 0; /* Determine ReadyMask */ @@ -352,7 +249,6 @@ int XHdcp1x_PortHdmiTxGetRepeaterInfo(const XHdcp1x_Port *InstancePtr, u16 *Info /* Check for repeater and ksv fifo ready */ if ((Value & ReadyMask) == ReadyMask) { - u8 Buf[2]; u16 U16Value = 0; @@ -379,22 +275,19 @@ int XHdcp1x_PortHdmiTxGetRepeaterInfo(const XHdcp1x_Port *InstancePtr, u16 *Info /*****************************************************************************/ /** +* This function reads a register from a HDCP port device. * -* This function reads a register from a hdcp port device +* @param InstancePtr is the device to read from. +* @param Offset is the offset to start reading from. +* @param Buf is the buffer to copy the data read. +* @param BufSize is the size of the buffer. * -* @param InstancePtr the device to read from -* @param Offset the offset to start reading from -* @param Buf the buffer to copy the data read -* @param BufSize the size of the buffer +* @return The number of bytes read. * -* @return -* The number of bytes read -* -* @note -* None. +* @note None. * ******************************************************************************/ -int XHdcp1x_PortHdmiTxRead(const XHdcp1x_Port* InstancePtr, u8 Offset, +int XHdcp1x_PortHdmiTxRead(const XHdcp1x_Port *InstancePtr, u8 Offset, void *Buf, u32 BufSize) { /* Verify arguments. */ @@ -412,19 +305,16 @@ int XHdcp1x_PortHdmiTxRead(const XHdcp1x_Port* InstancePtr, u8 Offset, /*****************************************************************************/ /** +* This function writes a register from a HDCP port device. * -* This function writes a register from a hdcp port device +* @param InstancePtr is the device to write to. +* @param Offset is the offset to start writing to. +* @param Buf is the buffer containing the data to write. +* @param BufSize is the size of the buffer. * -* @param InstancePtr the device to write to -* @param Offset the offset to start writing to -* @param Buf the buffer containing the data to write -* @param BufSize the size of the buffer +* @return The number of bytes written. * -* @return -* The number of bytes written -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_PortHdmiTxWrite(XHdcp1x_Port *InstancePtr, u8 Offset, @@ -445,7 +335,99 @@ int XHdcp1x_PortHdmiTxWrite(XHdcp1x_Port *InstancePtr, u8 Offset, /*****************************************************************************/ /** +* This reads a register from the HDCP port device. * +* @param InstancePtr is the device to read from. +* @param Offset is the offset to start reading from. +* @param Buf is the buffer to copy the data read. +* @param BufSize is the size of the buffer. +* +* @return The number of bytes read. +* +* @note None. +* +******************************************************************************/ +static int RegRead(const XHdcp1x_Port *InstancePtr, u8 Offset, u8 *Buf, + u32 BufSize) +{ + XHdmi_Tx *HdmiTx = InstancePtr->PhyIfPtr; + u8 Slave = 0x3Au; + int NumRead = 0; + + /* Write the address and check for failure */ + if (XHdmiTx_DdcWrite(HdmiTx, Slave, 1, &Offset, FALSE) + != XST_SUCCESS) { + NumRead = -1; + } + /* Read the data back and check for failure */ + else if (XHdmiTx_DdcRead(HdmiTx, Slave, BufSize, Buf, TRUE) + != XST_SUCCESS) { + NumRead = -2; + } + /* Success - just update NumRead */ + else { + NumRead = (int) BufSize; + } + + return (NumRead); +} + +/*****************************************************************************/ +/** +* This writes a register from the HDCP port device. +* +* @param InstancePtr is the device to write to. +* @param Offset is the offset to start writing at. +* @param Buf is the buffer containing the data to write. +* @param BufSize is the size of the buffer. +* +* @return The number of bytes written. +* +* @note None. +* +******************************************************************************/ +static int RegWrite(XHdcp1x_Port *InstancePtr, u8 Offset, const u8 *Buf, + u32 BufSize) +{ + XHdmi_Tx *HdmiTx = InstancePtr->PhyIfPtr; + u8 Slave = 0x3Au; + u8 TxBuf[WRITE_CHUNK_SZ + 1]; + int NumWritten = 0; + int ThisTime = 0; + + /* Iterate through the buffer */ + do { + /* Determine ThisTime */ + ThisTime = WRITE_CHUNK_SZ; + if (ThisTime > BufSize) { + ThisTime = BufSize; + } + + /* Format TxBuf */ + TxBuf[0] = Offset; + memcpy(&(TxBuf[1]), Buf, ThisTime); + + /* Write the TxBuf */ + if (XHdmiTx_DdcWrite(HdmiTx, Slave, (ThisTime + 1), TxBuf, TRUE) + != XST_SUCCESS) { + /* Update NumWritten and break */ + NumWritten = -1; + break; + } + + /* Update for loop */ + NumWritten += ThisTime; + Buf += ThisTime; + BufSize -= ThisTime; + } + while ((BufSize != 0) && (NumWritten > 0)); + + /* Return */ + return (NumWritten); +} + +/*****************************************************************************/ +/** * This tables defines the adaptor for the HDMI TX HDCP port driver * ******************************************************************************/ @@ -462,4 +444,5 @@ const XHdcp1x_PortPhyIfAdaptor XHdcp1x_PortHdmiTxAdaptor = NULL, }; -#endif /* defined(XPAR_XHDMI_TX_NUM_INSTANCES) && (XPAR_XHDMI_TX_NUM_INSTANCES > 0) */ +#endif +/* defined(XPAR_XHDMI_TX_NUM_INSTANCES) && (XPAR_XHDMI_TX_NUM_INSTANCES > 0) */ diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_intr.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_intr.c index 87110c52..ca7bb462 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_intr.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_port_intr.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -41,13 +41,13 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. -* 1.01 07/23/15 Additional documentation and formating +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ /***************************** Include Files *********************************/ + #include "xhdcp1x_port.h" #include "xil_assert.h" #include "xil_types.h" @@ -63,7 +63,6 @@ /*****************************************************************************/ /** -* * This function installs an asynchronous callback function for the given * HandlerType: * @@ -83,7 +82,7 @@ * - XST_SUCCESS if callback function installed successfully. * - XST_INVALID_PARAM when HandlerType is invalid. * -* @note Invoking this function for a handler that already has been +* @note Invoking this function for a handler that already has been * installed replaces it with the new handler. * ******************************************************************************/ @@ -100,17 +99,16 @@ int XHdcp1x_PortSetCallback(XHdcp1x_Port *InstancePtr, u32 HandlerType, /* Check for handler type */ switch (HandlerType) { + /* Authentication Callback */ + case (XHDCP1X_PORT_HANDLER_AUTHENTICATE): + InstancePtr->AuthCallback = CallbackFunc; + InstancePtr->AuthRef = CallbackRef; + InstancePtr->IsAuthCallbackSet = (TRUE); + break; - /* Authentication Callback */ - case (XHDCP1X_PORT_HANDLER_AUTHENTICATE): - InstancePtr->AuthCallback = CallbackFunc; - InstancePtr->AuthRef = CallbackRef; - InstancePtr->IsAuthCallbackSet = (TRUE); - break; - - default: - Status = (XST_INVALID_PARAM); - break; + default: + Status = (XST_INVALID_PARAM); + break; } return (Status); @@ -118,17 +116,14 @@ int XHdcp1x_PortSetCallback(XHdcp1x_Port *InstancePtr, u32 HandlerType, /*****************************************************************************/ /** +* This handles an interrupt generated by a HDCP port device. * -* This handles an interrupt generated by a hdcp port device +* @param InstancePtr is the device to write to. +* @param IntCause is the interrupt cause bit map. * -* @param InstancePtr the device to write to -* @param IntCause the interrupt cause bit map +* @return None. * -* @return -* void -* -* @note -* None. +* @note None. * ******************************************************************************/ void XHdcp1x_PortHandleInterrupt(XHdcp1x_Port *InstancePtr, u32 IntCause) @@ -141,11 +136,9 @@ void XHdcp1x_PortHandleInterrupt(XHdcp1x_Port *InstancePtr, u32 IntCause) /* Determine Adaptor */ Adaptor = InstancePtr->Adaptor; - /* Check for adaptor function and invoke if present*/ + /* Check for adaptor function and invoke if present */ if ((Adaptor != NULL) && (Adaptor->IntrHandler != NULL)) { InstancePtr->Stats.IntCount++; (*(Adaptor->IntrHandler))(InstancePtr, IntCause); } - - return; } diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_rx.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_rx.c index 3e7dceef..6ded836d 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_rx.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_rx.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,15 +42,14 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. -* 1.01 07/23/15 Additional documentation and formating +* 1.00 fidus 07/16/15 Initial release. * * *****************************************************************************/ /***************************** Include Files *********************************/ -#include "xparameters.h" +#include "xparameters.h" #include #include #include @@ -59,19 +58,19 @@ #include "xhdcp1x_debug.h" #include "xhdcp1x_port.h" #if defined(XPAR_XHDMI_RX_NUM_INSTANCES) && (XPAR_XHDMI_RX_NUM_INSTANCES > 0) - #include "xhdcp1x_port_hdmi.h" +#include "xhdcp1x_port_hdmi.h" #else - #include "xhdcp1x_port_dp.h" +#include "xhdcp1x_port_dp.h" #endif #include "xhdcp1x_rx.h" #include "xil_types.h" /************************** Constant Definitions *****************************/ + #define FLAG_PHY_UP (1u << 0) /**< Flag to track physical state */ /**************************** Type Definitions *******************************/ -typedef enum -{ +typedef enum { EVENT_NULL, EVENT_AUTHENTICATE, EVENT_CHECK, @@ -81,1071 +80,99 @@ typedef enum EVENT_PHYUP, EVENT_POLL, EVENT_UPDATERi, - } tEvent; -typedef enum -{ +typedef enum { STATE_DISABLED, STATE_UNAUTHENTICATED, STATE_COMPUTATIONS, STATE_AUTHENTICATED, STATE_LINKINTEGRITYFAILED, STATE_PHYDOWN, - } tState; /***************** Macros (Inline Functions) Definitions *********************/ /*****************************************************************************/ /** +* This queries an interface to determine if it is Display Port (DP). * -* This queries an interface to determine if it is Display Port (DP) +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating DP (TRUE) or not (FALSE). * -* @return -* Truth value indicating DP (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ #define IsDP(InstancePtr) (!InstancePtr->CfgPtr->IsHDMI) /*****************************************************************************/ /** +* This queries an interface to determine if it is HDMI. * -* This queries an interface to determine if it is HDMI +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating HDMI (TRUE) or not (FALSE). * -* @return -* Truth value indicating HDMI (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ #define IsHDMI(InstancePtr) (InstancePtr->CfgPtr->IsHDMI) +/*************************** Function Prototypes *****************************/ + +static void DebugLog(const XHdcp1x_Rx *InstancePtr, const char *LogMsg); +static void PostEvent(XHdcp1x_Rx *InstancePtr, tEvent Event); +static void AuthCallback(void *Parameter); +static void LinkFailCallback(void *Parameter); +static void RiUpdateCallback(void *Parameter); +static void SetCheckLinkState(XHdcp1x_Rx *InstancePtr, int IsEnabled); +static void Enable(XHdcp1x_Rx *InstancePtr); +static void Disable(XHdcp1x_Rx *InstancePtr); +static void StartComputations(XHdcp1x_Rx *InstancePtr, tState *NextStatePtr); +static void PollForComputations(XHdcp1x_Rx *InstancePtr, tState *NextStatePtr); +static void UpdateRi(XHdcp1x_Rx *InstancePtr, tState *NextStatePtr); +static void CheckLinkIntegrity(XHdcp1x_Rx *InstancePtr, tState *NextStatePtr); +static void ReportLinkIntegrityFailure(XHdcp1x_Rx *InstancePtr, + tState *NextStatePtr); +static void RunDisabledState(XHdcp1x_Rx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunUnauthenticatedState(XHdcp1x_Rx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunComputationsState(XHdcp1x_Rx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunAuthenticatedState(XHdcp1x_Rx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunLinkIntegrityFailedState(XHdcp1x_Rx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunPhysicalLayerDownState(XHdcp1x_Rx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void EnterState(XHdcp1x_Rx *InstancePtr, tState State, + tState *NextStatePtr); +static void ExitState(XHdcp1x_Rx *InstancePtr, tState State); +static void DoTheState(XHdcp1x_Rx *InstancePtr, tEvent Event); +static void Init(XHdcp1x_Rx *InstancePtr); +static void ProcessPending(XHdcp1x_Rx *InstancePtr); +static const char *StateToString(tState State); + /************************** Function Definitions *****************************/ /*****************************************************************************/ /** +* This function initializes the HDCP receiver module. * -* This function logs a debug message on behalf of a handler state machine -* -* @param InstancePtr the receiver instance -* @param LogMsg the message to log +* @param InstancePtr is the receiver instance. +* @param CfgPtr is the configuration of the instance. +* @param PhyIfPtr is a pointer to the underlying physical interface. * * @return -* void +* - XST_SUCCESS if successful. * -* @note -* None. -* -******************************************************************************/ -static void DebugLog(const XHdcp1x_Rx *InstancePtr, const char *LogMsg) -{ - char Label[16]; - - /* Format Label */ - snprintf(Label, 16, "hdcp-rx(%d) - ", InstancePtr->CfgPtr->DeviceId); - - /* Log it */ - XHDCP1X_DEBUG_LOGMSG(Label); - XHDCP1X_DEBUG_LOGMSG(LogMsg); - XHDCP1X_DEBUG_LOGMSG("\r\n"); - - return; -} - -/*****************************************************************************/ -/** -* -* This function posts an event to a state machine -* -* @param InstancePtr the receiver instance -* @param Event the event to post -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void PostEvent(XHdcp1x_Rx *InstancePtr, tEvent Event) -{ - /* Check for disable and clear any pending enable */ - if (Event == EVENT_DISABLE) { - InstancePtr->PendingEvents &= ~(1u << EVENT_ENABLE); - } - /* Check for phy-down and clear any pending phy-up */ - else if (Event == EVENT_PHYDOWN) { - InstancePtr->PendingEvents &= ~(1u << EVENT_PHYUP); - } - - /* Post it */ - InstancePtr->PendingEvents |= (1u << Event); - - return; -} - -/*****************************************************************************/ -/** -* -* This function acts as the re-authentication callback for a state machine -* -* @param Parameter the parameter specified during registration -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void AuthCallback(void *Parameter) -{ - XHdcp1x_Rx *InstancePtr = Parameter; - - /* Post the re-authentication request */ - PostEvent(InstancePtr, EVENT_AUTHENTICATE); - - return; -} - -/*****************************************************************************/ -/** -* -* This function acts as the link failure callback for a state machine -* -* @param Parameter the parameter specified during registration -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void LinkFailCallback(void *Parameter) -{ - XHdcp1x_Rx *InstancePtr = Parameter; - - /* Post the check request */ - PostEvent(InstancePtr, EVENT_CHECK); - - return; -} - -/*****************************************************************************/ -/** -* -* This function acts as the Ri register update callback for a state machine -* -* @param Parameter the parameter specified during registration -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RiUpdateCallback(void *Parameter) -{ - XHdcp1x_Rx *InstancePtr = Parameter; - - /* Post the update Ri request */ - PostEvent(InstancePtr, EVENT_UPDATERi); - - return; -} - -/*****************************************************************************/ -/** -* -* This function sets the check link state of the handler -* -* @param InstancePtr the receiver instance -* @param IsEnabled truth value indicating on/off -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void SetCheckLinkState(XHdcp1x_Rx *InstancePtr, int IsEnabled) -{ - XHdcp1x_Cipher *CipherPtr = &(InstancePtr->Cipher); - - /* Check for DP */ - if (IsDP(InstancePtr)) { - XHdcp1x_CipherSetLinkStateCheck(CipherPtr, IsEnabled); - } - /* Check for HDMI */ - else if (IsHDMI(InstancePtr)) { - XHdcp1x_CipherSetRiUpdate(CipherPtr, IsEnabled); - } - - /* Return */ - return; -} - -/*****************************************************************************/ -/** -* -* This function enables a receiver state machine -* -* @param InstancePtr the receiver instance -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void Enable(XHdcp1x_Rx *InstancePtr) -{ - XHdcp1x_Cipher *CipherPtr = &(InstancePtr->Cipher); - XHdcp1x_Port *PortPtr = &(InstancePtr->Port); - u64 MyKsv = 0; - u8 Buf[8]; - - /* Disable and register the link failure callback */ - XHdcp1x_CipherSetLinkStateCheck(CipherPtr, FALSE); - XHdcp1x_CipherSetCallback(CipherPtr, - XHDCP1X_CIPHER_HANDLER_LINK_FAILURE, - &LinkFailCallback, InstancePtr); - - /* Disable and register the Ri callback */ - XHdcp1x_CipherSetRiUpdate(CipherPtr, FALSE); - XHdcp1x_CipherSetCallback(CipherPtr, - XHDCP1X_CIPHER_HANDLER_Ri_UPDATE, - &RiUpdateCallback, InstancePtr); - - /* Enable the crypto engine */ - XHdcp1x_CipherEnable(CipherPtr); - - /* Read MyKsv */ - MyKsv = XHdcp1x_CipherGetLocalKsv(CipherPtr); - - /* If unknown - try against for good luck */ - if (MyKsv == 0) { - MyKsv = XHdcp1x_CipherGetLocalKsv(CipherPtr); - } - - /* Initialize Bksv */ - memset(Buf, 0, 8); - XHDCP1X_PORT_UINT_TO_BUF(Buf, MyKsv, XHDCP1X_PORT_SIZE_BKSV*8); - XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_BKSV, Buf, - XHDCP1X_PORT_SIZE_BKSV); - - /* Register the re-authentication callback */ - XHdcp1x_PortSetCallback(PortPtr, XHDCP1X_PORT_HANDLER_AUTHENTICATE, - &AuthCallback, InstancePtr); - - /* Enable the hdcp port */ - XHdcp1x_PortEnable(PortPtr); - - return; -} - -/*****************************************************************************/ -/** -* -* This function disables a receiver state machine -* -* @param InstancePtr the receiver instance -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void Disable(XHdcp1x_Rx *InstancePtr) -{ - /* Disable the hdcp cipher and port */ - XHdcp1x_PortDisable(&(InstancePtr->Port)); - XHdcp1x_CipherDisable(&(InstancePtr->Cipher)); - - /* Clear statistics */ - memset(&(InstancePtr->Stats), 0, sizeof(InstancePtr->Stats)); - - return; -} - -/*****************************************************************************/ -/** -* -* This function initiates the computations for a receiver state machine -* -* @param InstancePtr the receiver instance -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void StartComputations(XHdcp1x_Rx *InstancePtr, tState *NextStatePtr) -{ - XHdcp1x_Cipher *CipherPtr = &(InstancePtr->Cipher); - XHdcp1x_Port *PortPtr = &(InstancePtr->Port); - u8 Buf[8]; - u64 Value = 0; - u32 X = 0; - u32 Y = 0; - u32 Z = 0; - - /* Log */ - DebugLog(InstancePtr, "starting computations"); - - /* Update statistics */ - InstancePtr->Stats.AuthAttempts++; - - /* Determine theAKsv */ - memset(Buf, 0, 8); - XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_AKSV, Buf, - XHDCP1X_PORT_SIZE_AKSV); - XHDCP1X_PORT_BUF_TO_UINT(Value, Buf, XHDCP1X_PORT_SIZE_AKSV*8); - - /* Load the cipher with the remote ksv */ - XHdcp1x_CipherSetRemoteKsv(CipherPtr, Value); - - /* Update theU64Value with An */ - memset(Buf, 0, 8); - XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_AN, Buf, - XHDCP1X_PORT_SIZE_AN); - XHDCP1X_PORT_BUF_TO_UINT(Value, Buf, XHDCP1X_PORT_SIZE_AN*8); - - /* Load the cipher B registers with An */ - X = (u32) (Value & 0x0FFFFFFFul); - Value >>= 28; - Y = (u32) (Value & 0x0FFFFFFFul); - Value >>= 28; - Z = (u32) (Value & 0x000000FFul); - XHdcp1x_CipherSetB(CipherPtr, X, Y, Z); - - /* Initiate the block cipher */ - XHdcp1x_CipherDoRequest(CipherPtr, XHDCP1X_CIPHER_REQUEST_BLOCK); - - /* Return */ - return; -} - -/*****************************************************************************/ -/** -* -* This function polls the progress of the computations for a state machine -* -* @param InstancePtr the receiver instance -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void PollForComputations(XHdcp1x_Rx *InstancePtr, tState *NextStatePtr) -{ - XHdcp1x_Cipher *CipherPtr = &(InstancePtr->Cipher); - - /* Check for done */ - if (XHdcp1x_CipherIsRequestComplete(CipherPtr)) { - XHdcp1x_Port *PortPtr = &(InstancePtr->Port); - u8 Buf[4]; - u16 Ro = 0; - - /* Log */ - DebugLog(InstancePtr, "computations complete"); - - /* Read theRo */ - Ro = XHdcp1x_CipherGetRo(CipherPtr); - - /* Initialize Buf */ - memset(Buf, 0, 4); - XHDCP1X_PORT_UINT_TO_BUF(Buf, Ro, 16); - - /* Update the value of Ro' */ - XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_RO, Buf, 2); - -#if defined(XHDCP1X_PORT_BIT_BSTATUS_RO_AVAILABLE) - /* Update the Bstatus to indicate Ro' available */ - XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_BSTATUS, Buf, - XHDCP1X_PORT_SIZE_BSTATUS); - Buf[0] |= XHDCP1X_PORT_BIT_BSTATUS_RO_AVAILABLE; - XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_BSTATUS, Buf, - XHDCP1X_PORT_SIZE_BSTATUS); -#endif - - /* Update NextStatePtr */ - *NextStatePtr = STATE_AUTHENTICATED; - } - else { - DebugLog(InstancePtr, "waiting for computations"); - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function updates the Ro'/Ri' register of the state machine -* -* @param InstancePtr the receiver instance -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* This function has to save the value of Ri (in RememberRi) as the macro -* that converts from a uint16 to a HDCP buffer destroys the original value -* -******************************************************************************/ -static void UpdateRi(XHdcp1x_Rx *InstancePtr, tState *NextStatePtr) -{ - XHdcp1x_Cipher *CipherPtr = &(InstancePtr->Cipher); - XHdcp1x_Port *PortPtr = &(InstancePtr->Port); - char LogBuf[20]; - u8 Buf[4]; - u16 Ri = 0; - u16 RememberRi = 0; - - /* Read Ri */ - Ri = XHdcp1x_CipherGetRi(CipherPtr); - - /* Update RememberRi */ - RememberRi = Ri; - - /* Initialize theBuf */ - memset(Buf, 0, 4); - XHDCP1X_PORT_UINT_TO_BUF(Buf, Ri, XHDCP1X_PORT_SIZE_RO*8); - - /* Update the value of Ro' */ - XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_RO, Buf, sizeof(Ri)); - -#if defined(XHDCP1X_PORT_BIT_BSTATUS_RO_AVAILABLE) - /* Update the Bstatus to indicate Ro' available */ - XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_BSTATUS, Buf, - XHDCP1X_PORT_SIZE_BSTATUS); - Buf[0] |= XHDCP1X_PORT_BIT_BSTATUS_RO_AVAILABLE; - XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_BSTATUS, Buf, - XHDCP1X_PORT_SIZE_BSTATUS); -#endif - - /* Update statistics */ - InstancePtr->Stats.RiUpdates++; - - /* Determine theLogBuf */ - snprintf(LogBuf, 20, "update Ri (%04X)", RememberRi); - - /* Log */ - DebugLog(InstancePtr, LogBuf); - - return; -} - -/*****************************************************************************/ -/** -* -* This functions handles check the integrity of the link -* -* @param InstancePtr the receiver instance -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None -* -******************************************************************************/ -static void CheckLinkIntegrity(XHdcp1x_Rx *InstancePtr, tState *NextStatePtr) -{ - if (XHdcp1x_CipherIsLinkUp(&(InstancePtr->Cipher))) { - *NextStatePtr = STATE_AUTHENTICATED; - } - else { - *NextStatePtr = STATE_LINKINTEGRITYFAILED; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This functions reports the failure of link integrity -* -* @param InstancePtr the receiver instance -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None -* -******************************************************************************/ -static void ReportLinkIntegrityFailure(XHdcp1x_Rx *InstancePtr, - tState *NextStatePtr) -{ -#if defined(XHDCP1X_PORT_BIT_BSTATUS_LINK_FAILURE) - XHdcp1x_Port *PortPtr = &(InstancePtr->Port); - u8 Buf[XHDCP1X_PORT_SIZE_BSTATUS]; - - /* Update the Bstatus register */ - XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_BSTATUS, Buf, - XHDCP1X_PORT_SIZE_BSTATUS); - Buf[0] |= XHDCP1X_PORT_BIT_BSTATUS_LINK_FAILURE; - XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_BSTATUS, Buf, - XHDCP1X_PORT_SIZE_BSTATUS); -#endif - - /* Log */ - DebugLog(InstancePtr, "link integrity failed"); - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "disabled" state of the receiver state machine -* -* @param InstancePtr the receiver instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunDisabledState(XHdcp1x_Rx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For enable */ - case EVENT_ENABLE: - *NextStatePtr = STATE_UNAUTHENTICATED; - if ((InstancePtr->Flags & FLAG_PHY_UP) == 0) - *NextStatePtr = STATE_PHYDOWN; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - InstancePtr->Flags &= ~FLAG_PHY_UP; - break; - /* For physical layer up */ - case EVENT_PHYUP: - InstancePtr->Flags |= FLAG_PHY_UP; - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "unauthenticated" state of the receiver state machine -* -* @param InstancePtr the receiver instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunUnauthenticatedState(XHdcp1x_Rx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For authenticate */ - case EVENT_AUTHENTICATE: - *NextStatePtr = STATE_COMPUTATIONS; - break; - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "computations" state of the receiver state machine -* -* @param InstancePtr the receiver instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunComputationsState(XHdcp1x_Rx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For authenticate */ - case EVENT_AUTHENTICATE: - StartComputations(InstancePtr, NextStatePtr); - break; - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* For poll */ - case EVENT_POLL: - PollForComputations(InstancePtr, NextStatePtr); - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "authenticated" state of the receiver state machine -* -* @param InstancePtr the receiver instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunAuthenticatedState(XHdcp1x_Rx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For authenticate */ - case EVENT_AUTHENTICATE: - *NextStatePtr = STATE_COMPUTATIONS; - break; - /* For check */ - case EVENT_CHECK: - CheckLinkIntegrity(InstancePtr, NextStatePtr); - break; - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* For update Ri */ - case EVENT_UPDATERi: - UpdateRi(InstancePtr, NextStatePtr); - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "link integrity failed" state of the receiver state -* machine -* -* @param InstancePtr the receiver instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunLinkIntegrityFailedState(XHdcp1x_Rx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For authenticate */ - case EVENT_AUTHENTICATE: - *NextStatePtr = STATE_COMPUTATIONS; - break; - /* For check */ - case EVENT_CHECK: - CheckLinkIntegrity(InstancePtr, NextStatePtr); - break; - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "physical layer down" state of the receiver state -* machine -* -* @param InstancePtr the receiver instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunPhysicalLayerDownState(XHdcp1x_Rx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer up */ - case EVENT_PHYUP: - *NextStatePtr = STATE_UNAUTHENTICATED; - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function enters a hdcp receiver state -* -* @param InstancePtr the receiver instance -* @param State the state to enter -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void EnterState(XHdcp1x_Rx *InstancePtr, tState State, - tState *NextStatePtr) -{ - /* Which state? */ - switch (State) { - - /* For the disabled state */ - case STATE_DISABLED: - Disable(InstancePtr); - break; - /* For the unauthenticated state */ - case STATE_UNAUTHENTICATED: - InstancePtr->Flags |= FLAG_PHY_UP; - break; - /* For the computations state */ - case STATE_COMPUTATIONS: - StartComputations(InstancePtr, NextStatePtr); - break; - /* For the authenticated state */ - case STATE_AUTHENTICATED: - DebugLog(InstancePtr, "authenticated"); - SetCheckLinkState(InstancePtr, TRUE); - break; - /* For the link integrity failed state */ - case STATE_LINKINTEGRITYFAILED: - InstancePtr->Stats.LinkFailures++; - ReportLinkIntegrityFailure(InstancePtr, NextStatePtr); - break; - /* For physical layer down */ - case STATE_PHYDOWN: - InstancePtr->Flags &= ~FLAG_PHY_UP; - XHdcp1x_CipherDisable(&(InstancePtr->Cipher)); - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function exits a hdcp receiver state -* -* @param InstancePtr the receiver instance -* @param State the state to exit -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void ExitState(XHdcp1x_Rx *InstancePtr, tState State) -{ - /* Which state? */ - switch (State) { - - /* For the disabled state */ - case STATE_DISABLED: - Enable(InstancePtr); - break; - /* For the authenticated state */ - case STATE_AUTHENTICATED: - SetCheckLinkState(InstancePtr, FALSE); - break; - /* For physical layer down */ - case STATE_PHYDOWN: - XHdcp1x_CipherEnable(&(InstancePtr->Cipher)); - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function drives a hdcp receiver state machine -* -* @param InstancePtr the receiver instance -* @param Event the event to process -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void DoTheState(XHdcp1x_Rx *InstancePtr, tEvent Event) -{ - tState NextState = InstancePtr->CurrentState; - - /* Which state? */ - switch (InstancePtr->CurrentState) { - - /* For the disabled state */ - case STATE_DISABLED: - RunDisabledState(InstancePtr, Event, &NextState); - break; - /* For the unauthenticated state */ - case STATE_UNAUTHENTICATED: - RunUnauthenticatedState(InstancePtr, Event, &NextState); - break; - /* For the computations state */ - case STATE_COMPUTATIONS: - RunComputationsState(InstancePtr, Event, &NextState); - break; - /* For the authenticated state */ - case STATE_AUTHENTICATED: - RunAuthenticatedState(InstancePtr, Event, &NextState); - break; - /* For the link integrity failed state */ - case STATE_LINKINTEGRITYFAILED: - RunLinkIntegrityFailedState(InstancePtr, Event, &NextState); - break; - /* For the physical layer down state */ - case STATE_PHYDOWN: - RunPhysicalLayerDownState(InstancePtr, Event, &NextState); - break; - /* Otherwise */ - default: - break; - } - - /* Check for state change */ - while (InstancePtr->CurrentState != NextState) { - - /* Perform the state transition */ - ExitState(InstancePtr, InstancePtr->CurrentState); - InstancePtr->PreviousState = InstancePtr->CurrentState; - InstancePtr->CurrentState = NextState; - EnterState(InstancePtr, InstancePtr->CurrentState, &NextState); - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function initializes a hdcp receiver state machine -* -* @param InstancePtr the receiver instance -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void Init(XHdcp1x_Rx *InstancePtr) -{ - tState DummyState = STATE_DISABLED; - - /* Update theHandler */ - InstancePtr->PendingEvents = 0; - - /* Kick the state machine */ - EnterState(InstancePtr, STATE_DISABLED, &DummyState); - - return; -} - -/*****************************************************************************/ -/** -* -* This function processes the events pending on a state machine -* -* @param InstancePtr the receiver instance -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void ProcessPending(XHdcp1x_Rx *InstancePtr) -{ - /* Check for any pending events */ - if (InstancePtr->PendingEvents != 0) { - u16 Pending = InstancePtr->PendingEvents; - tEvent Event = EVENT_NULL; - - /* Update InstancePtr */ - InstancePtr->PendingEvents = 0; - - /* Iterate through thePending */ - do { - /* Check for a pending event */ - if ((Pending & 1u) != 0) { - DoTheState(InstancePtr, Event); - } - - /* Update for loop */ - Pending >>= 1; - Event++; - } - while (Pending != 0); - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function initializes the hdcp receiver module -* -* @param InstancePtr the receiver instance -* @param CfgPtr the configuration of the instance -* @param PhyIfPtr pointer to the underlying physical interface -* -* @return -* XST_SUCCESS if successful. -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_RxCfgInitialize(XHdcp1x_Rx *InstancePtr, - const XHdcp1x_Config *CfgPtr, void* PhyIfPtr) + const XHdcp1x_Config *CfgPtr, void *PhyIfPtr) { XHdcp1x_Cipher *CipherPtr = NULL; XHdcp1x_Port *PortPtr = NULL; @@ -1176,16 +203,14 @@ int XHdcp1x_RxCfgInitialize(XHdcp1x_Rx *InstancePtr, /*****************************************************************************/ /** +* This function polls the HDCP receiver module. * -* This function polls the hdcp receiver module -* -* @param InstancePtr the receiver instance +* @param InstancePtr is the receiver instance. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_RxPoll(XHdcp1x_Rx *InstancePtr) @@ -1206,16 +231,14 @@ int XHdcp1x_RxPoll(XHdcp1x_Rx *InstancePtr) /*****************************************************************************/ /** +* This function resets an HDCP interface. * -* This function resets an hdcp interface -* -* @param InstancePtr the transmitter instance +* @param InstancePtr is the transmitter instance. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* This function disables and then re-enables the interface. +* @note This function disables and then re-enables the interface. * ******************************************************************************/ int XHdcp1x_RxReset(XHdcp1x_Rx *InstancePtr) @@ -1234,16 +257,14 @@ int XHdcp1x_RxReset(XHdcp1x_Rx *InstancePtr) /*****************************************************************************/ /** +* This function enables a HDCP receive interface. * -* This function enables a hdcp receive interface -* -* @param InstancePtr the receiver instance +* @param InstancePtr is the receiver instance. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_RxEnable(XHdcp1x_Rx *InstancePtr) @@ -1261,16 +282,14 @@ int XHdcp1x_RxEnable(XHdcp1x_Rx *InstancePtr) /*****************************************************************************/ /** +* This function disables a HDCP receive interface. * -* This function disables a hdcp receive interface -* -* @param InstancePtr the receiver instance +* @param InstancePtr is the receiver instance. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_RxDisable(XHdcp1x_Rx *InstancePtr) @@ -1288,17 +307,15 @@ int XHdcp1x_RxDisable(XHdcp1x_Rx *InstancePtr) /*****************************************************************************/ /** +* This function updates the physical state of an HDCP interface. * -* This function updates the physical state of an hdcp interface -* -* @param InstancePtr the receiver instance -* @param IsUp truth value indicating the status of physical interface +* @param InstancePtr is the receiver instance. +* @param IsUp is truth value indicating the status of physical interface. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_RxSetPhysicalState(XHdcp1x_Rx *InstancePtr, int IsUp) @@ -1322,17 +339,15 @@ int XHdcp1x_RxSetPhysicalState(XHdcp1x_Rx *InstancePtr, int IsUp) /*****************************************************************************/ /** +* This function set the lane count of an hdcp interface. * -* This function set the lane count of an hdcp interface -* -* @param InstancePtr the receiver instance -* @param LaneCount the number of lanes of the interface +* @param InstancePtr is the receiver instance. +* @param LaneCount is the number of lanes of the interface. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_RxSetLaneCount(XHdcp1x_Rx *InstancePtr, int LaneCount) @@ -1347,16 +362,14 @@ int XHdcp1x_RxSetLaneCount(XHdcp1x_Rx *InstancePtr, int LaneCount) /*****************************************************************************/ /** +* This function initiates authentication on an interface. * -* This function initiates authentication on an interface -* -* @param InstancePtr the receiver instance +* @param InstancePtr is the receiver instance. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_RxAuthenticate(XHdcp1x_Rx *InstancePtr) @@ -1374,16 +387,13 @@ int XHdcp1x_RxAuthenticate(XHdcp1x_Rx *InstancePtr) /*****************************************************************************/ /** +* This function queries an interface to check if its been authenticated. * -* This function queries an interface to check if its been authenticated +* @param InstancePtr is the receiver instance. * -* @param InstancePtr the receiver instance +* @return Truth value indicating authenticated (true) or not (false). * -* @return -* Truth value indicating authenticated (true) or not (false) -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_RxIsAuthenticated(const XHdcp1x_Rx *InstancePtr) @@ -1403,16 +413,13 @@ int XHdcp1x_RxIsAuthenticated(const XHdcp1x_Rx *InstancePtr) /*****************************************************************************/ /** +* This function retrieves the current encryption stream map. * -* This function retrieves the current encryption stream map +* @param InstancePtr is the receiver instance. * -* @param InstancePtr the receiver instance +* @return The current encryption stream map. * -* @return -* The current encryption stream map -* -* @note -* None. +* @note None. * ******************************************************************************/ u64 XHdcp1x_RxGetEncryption(const XHdcp1x_Rx *InstancePtr) @@ -1426,63 +433,14 @@ u64 XHdcp1x_RxGetEncryption(const XHdcp1x_Rx *InstancePtr) /*****************************************************************************/ /** +* This function implements the debug display output for receiver instances. * -* This function converts from a state to a display string -* -* @param State the state to convert +* @param InstancePtr is the receiver instance. * * @return -* The corresponding display string +* - XST_SUCCESS if successful. * -* @note -* None. -* -******************************************************************************/ -static const char* StateToString(tState State) -{ - const char* String = NULL; - - /* Which state? */ - switch (State) { - - case STATE_DISABLED: - String = "disabled"; - break; - case STATE_UNAUTHENTICATED: - String = "unauthenticated"; - break; - case STATE_COMPUTATIONS: - String = "computations"; - break; - case STATE_AUTHENTICATED: - String = "authenticated"; - break; - case STATE_LINKINTEGRITYFAILED: - String = "link-integrity-failed"; - break; - case STATE_PHYDOWN: - String = "physical-layer-down"; - break; - default: - String = "???"; - break; - } - - return (String); -} - -/*****************************************************************************/ -/** -* -* This function implements the debug display output for receiver instances -* -* @param InstancePtr the receiver instance -* -* @return -* XST_SUCCESS if successful. -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_RxInfo(const XHdcp1x_Rx *InstancePtr) @@ -1535,3 +493,956 @@ int XHdcp1x_RxInfo(const XHdcp1x_Rx *InstancePtr) return (XST_SUCCESS); } + +/*****************************************************************************/ +/** +* This function logs a debug message on behalf of a handler state machine. +* +* @param InstancePtr is the receiver instance. +* @param LogMsg is the message to log. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void DebugLog(const XHdcp1x_Rx *InstancePtr, const char *LogMsg) +{ + char Label[16]; + + /* Format Label */ + snprintf(Label, 16, "hdcp-rx(%d) - ", InstancePtr->CfgPtr->DeviceId); + + /* Log it */ + XHDCP1X_DEBUG_LOGMSG(Label); + XHDCP1X_DEBUG_LOGMSG(LogMsg); + XHDCP1X_DEBUG_LOGMSG("\r\n"); +} + +/*****************************************************************************/ +/** +* This function posts an event to a state machine. +* +* @param InstancePtr is the receiver instance. +* @param Event is the event to post. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void PostEvent(XHdcp1x_Rx *InstancePtr, tEvent Event) +{ + /* Check for disable and clear any pending enable */ + if (Event == EVENT_DISABLE) { + InstancePtr->PendingEvents &= ~(1u << EVENT_ENABLE); + } + /* Check for phy-down and clear any pending phy-up */ + else if (Event == EVENT_PHYDOWN) { + InstancePtr->PendingEvents &= ~(1u << EVENT_PHYUP); + } + + /* Post it */ + InstancePtr->PendingEvents |= (1u << Event); +} + +/*****************************************************************************/ +/** +* This function acts as the re-authentication callback for a state machine. +* +* @param Parameter is the parameter specified during registration. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void AuthCallback(void *Parameter) +{ + XHdcp1x_Rx *InstancePtr = Parameter; + + /* Post the re-authentication request */ + PostEvent(InstancePtr, EVENT_AUTHENTICATE); +} + +/*****************************************************************************/ +/** +* This function acts as the link failure callback for a state machine. +* +* @param Parameter is the parameter specified during registration. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void LinkFailCallback(void *Parameter) +{ + XHdcp1x_Rx *InstancePtr = Parameter; + + /* Post the check request */ + PostEvent(InstancePtr, EVENT_CHECK); +} + +/*****************************************************************************/ +/** +* This function acts as the Ri register update callback for a state machine. +* +* @param Parameter is the parameter specified during registration. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RiUpdateCallback(void *Parameter) +{ + XHdcp1x_Rx *InstancePtr = Parameter; + + /* Post the update Ri request */ + PostEvent(InstancePtr, EVENT_UPDATERi); +} + +/*****************************************************************************/ +/** +* This function sets the check link state of the handler. +* +* @param InstancePtr is the receiver instance. +* @param IsEnabled is truth value indicating on/off. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void SetCheckLinkState(XHdcp1x_Rx *InstancePtr, int IsEnabled) +{ + XHdcp1x_Cipher *CipherPtr = &(InstancePtr->Cipher); + + /* Check for DP */ + if (IsDP(InstancePtr)) { + XHdcp1x_CipherSetLinkStateCheck(CipherPtr, IsEnabled); + } + /* Check for HDMI */ + else if (IsHDMI(InstancePtr)) { + XHdcp1x_CipherSetRiUpdate(CipherPtr, IsEnabled); + } +} + +/*****************************************************************************/ +/** +* This function enables a receiver state machine. +* +* @param InstancePtr is the receiver instance. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void Enable(XHdcp1x_Rx *InstancePtr) +{ + XHdcp1x_Cipher *CipherPtr = &(InstancePtr->Cipher); + XHdcp1x_Port *PortPtr = &(InstancePtr->Port); + u64 MyKsv = 0; + u8 Buf[8]; + + /* Disable and register the link failure callback */ + XHdcp1x_CipherSetLinkStateCheck(CipherPtr, FALSE); + XHdcp1x_CipherSetCallback(CipherPtr, + XHDCP1X_CIPHER_HANDLER_LINK_FAILURE, + &LinkFailCallback, InstancePtr); + + /* Disable and register the Ri callback */ + XHdcp1x_CipherSetRiUpdate(CipherPtr, FALSE); + XHdcp1x_CipherSetCallback(CipherPtr, + XHDCP1X_CIPHER_HANDLER_Ri_UPDATE, + &RiUpdateCallback, InstancePtr); + + /* Enable the crypto engine */ + XHdcp1x_CipherEnable(CipherPtr); + + /* Read MyKsv */ + MyKsv = XHdcp1x_CipherGetLocalKsv(CipherPtr); + + /* If unknown - try against for good luck */ + if (MyKsv == 0) { + MyKsv = XHdcp1x_CipherGetLocalKsv(CipherPtr); + } + + /* Initialize Bksv */ + memset(Buf, 0, 8); + XHDCP1X_PORT_UINT_TO_BUF(Buf, MyKsv, XHDCP1X_PORT_SIZE_BKSV * 8); + XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_BKSV, Buf, + XHDCP1X_PORT_SIZE_BKSV); + + /* Register the re-authentication callback */ + XHdcp1x_PortSetCallback(PortPtr, XHDCP1X_PORT_HANDLER_AUTHENTICATE, + &AuthCallback, InstancePtr); + + /* Enable the hdcp port */ + XHdcp1x_PortEnable(PortPtr); +} + +/*****************************************************************************/ +/** +* This function disables a receiver state machine. +* +* @param InstancePtr is the receiver instance. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void Disable(XHdcp1x_Rx *InstancePtr) +{ + /* Disable the hdcp cipher and port */ + XHdcp1x_PortDisable(&(InstancePtr->Port)); + XHdcp1x_CipherDisable(&(InstancePtr->Cipher)); + + /* Clear statistics */ + memset(&(InstancePtr->Stats), 0, sizeof(InstancePtr->Stats)); +} + +/*****************************************************************************/ +/** +* This function initiates the computations for a receiver state machine. +* +* @param InstancePtr is the receiver instance. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void StartComputations(XHdcp1x_Rx *InstancePtr, tState *NextStatePtr) +{ + XHdcp1x_Cipher *CipherPtr = &(InstancePtr->Cipher); + XHdcp1x_Port *PortPtr = &(InstancePtr->Port); + u8 Buf[8]; + u64 Value = 0; + u32 X = 0; + u32 Y = 0; + u32 Z = 0; + + /* Log */ + DebugLog(InstancePtr, "starting computations"); + + /* Update statistics */ + InstancePtr->Stats.AuthAttempts++; + + /* Determine theAKsv */ + memset(Buf, 0, 8); + XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_AKSV, Buf, + XHDCP1X_PORT_SIZE_AKSV); + XHDCP1X_PORT_BUF_TO_UINT(Value, Buf, XHDCP1X_PORT_SIZE_AKSV * 8); + + /* Load the cipher with the remote ksv */ + XHdcp1x_CipherSetRemoteKsv(CipherPtr, Value); + + /* Update theU64Value with An */ + memset(Buf, 0, 8); + XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_AN, Buf, + XHDCP1X_PORT_SIZE_AN); + XHDCP1X_PORT_BUF_TO_UINT(Value, Buf, XHDCP1X_PORT_SIZE_AN * 8); + + /* Load the cipher B registers with An */ + X = (u32) (Value & 0x0FFFFFFFul); + Value >>= 28; + Y = (u32) (Value & 0x0FFFFFFFul); + Value >>= 28; + Z = (u32) (Value & 0x000000FFul); + XHdcp1x_CipherSetB(CipherPtr, X, Y, Z); + + /* Initiate the block cipher */ + XHdcp1x_CipherDoRequest(CipherPtr, XHDCP1X_CIPHER_REQUEST_BLOCK); +} + +/*****************************************************************************/ +/** +* This function polls the progress of the computations for a state machine. +* +* @param InstancePtr is the receiver instance. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void PollForComputations(XHdcp1x_Rx *InstancePtr, tState *NextStatePtr) +{ + XHdcp1x_Cipher *CipherPtr = &(InstancePtr->Cipher); + + /* Check for done */ + if (XHdcp1x_CipherIsRequestComplete(CipherPtr)) { + XHdcp1x_Port *PortPtr = &(InstancePtr->Port); + u8 Buf[4]; + u16 Ro = 0; + + /* Log */ + DebugLog(InstancePtr, "computations complete"); + + /* Read theRo */ + Ro = XHdcp1x_CipherGetRo(CipherPtr); + + /* Initialize Buf */ + memset(Buf, 0, 4); + XHDCP1X_PORT_UINT_TO_BUF(Buf, Ro, 16); + + /* Update the value of Ro' */ + XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_RO, Buf, 2); + +#if defined(XHDCP1X_PORT_BIT_BSTATUS_RO_AVAILABLE) + /* Update the Bstatus to indicate Ro' available */ + XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_BSTATUS, Buf, + XHDCP1X_PORT_SIZE_BSTATUS); + Buf[0] |= XHDCP1X_PORT_BIT_BSTATUS_RO_AVAILABLE; + XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_BSTATUS, Buf, + XHDCP1X_PORT_SIZE_BSTATUS); +#endif + /* Update NextStatePtr */ + *NextStatePtr = STATE_AUTHENTICATED; + } + else { + DebugLog(InstancePtr, "waiting for computations"); + } +} + +/*****************************************************************************/ +/** +* This function updates the Ro'/Ri' register of the state machine. +* +* @param InstancePtr is the receiver instance. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note This function has to save the value of Ri (in RememberRi) as the +* macro that converts from a uint16 to a HDCP buffer destroys the +* original value. +* +******************************************************************************/ +static void UpdateRi(XHdcp1x_Rx *InstancePtr, tState *NextStatePtr) +{ + XHdcp1x_Cipher *CipherPtr = &(InstancePtr->Cipher); + XHdcp1x_Port *PortPtr = &(InstancePtr->Port); + char LogBuf[20]; + u8 Buf[4]; + u16 Ri = 0; + u16 RememberRi = 0; + + /* Read Ri */ + Ri = XHdcp1x_CipherGetRi(CipherPtr); + + /* Update RememberRi */ + RememberRi = Ri; + + /* Initialize theBuf */ + memset(Buf, 0, 4); + XHDCP1X_PORT_UINT_TO_BUF(Buf, Ri, XHDCP1X_PORT_SIZE_RO * 8); + + /* Update the value of Ro' */ + XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_RO, Buf, sizeof(Ri)); + +#if defined(XHDCP1X_PORT_BIT_BSTATUS_RO_AVAILABLE) + /* Update the Bstatus to indicate Ro' available */ + XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_BSTATUS, Buf, + XHDCP1X_PORT_SIZE_BSTATUS); + Buf[0] |= XHDCP1X_PORT_BIT_BSTATUS_RO_AVAILABLE; + XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_BSTATUS, Buf, + XHDCP1X_PORT_SIZE_BSTATUS); +#endif + + /* Update statistics */ + InstancePtr->Stats.RiUpdates++; + + /* Determine theLogBuf */ + snprintf(LogBuf, 20, "update Ri (%04X)", RememberRi); + + /* Log */ + DebugLog(InstancePtr, LogBuf); +} + +/*****************************************************************************/ +/** +* This functions handles check the integrity of the link. +* +* @param InstancePtr is the receiver instance. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void CheckLinkIntegrity(XHdcp1x_Rx *InstancePtr, tState *NextStatePtr) +{ + if (XHdcp1x_CipherIsLinkUp(&(InstancePtr->Cipher))) { + *NextStatePtr = STATE_AUTHENTICATED; + } + else { + *NextStatePtr = STATE_LINKINTEGRITYFAILED; + } +} + +/*****************************************************************************/ +/** +* This functions reports the failure of link integrity. +* +* @param InstancePtr is the receiver instance. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void ReportLinkIntegrityFailure(XHdcp1x_Rx *InstancePtr, + tState *NextStatePtr) +{ +#if defined(XHDCP1X_PORT_BIT_BSTATUS_LINK_FAILURE) + XHdcp1x_Port *PortPtr = &(InstancePtr->Port); + u8 Buf[XHDCP1X_PORT_SIZE_BSTATUS]; + + /* Update the Bstatus register */ + XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_BSTATUS, Buf, + XHDCP1X_PORT_SIZE_BSTATUS); + Buf[0] |= XHDCP1X_PORT_BIT_BSTATUS_LINK_FAILURE; + XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_BSTATUS, Buf, + XHDCP1X_PORT_SIZE_BSTATUS); +#endif + + /* Log */ + DebugLog(InstancePtr, "link integrity failed"); +} + +/*****************************************************************************/ +/** +* This function runs the "disabled" state of the receiver state machine. +* +* @param InstancePtr is the receiver instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunDisabledState(XHdcp1x_Rx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For enable */ + case EVENT_ENABLE: + *NextStatePtr = STATE_UNAUTHENTICATED; + if ((InstancePtr->Flags & FLAG_PHY_UP) == 0) { + *NextStatePtr = STATE_PHYDOWN; + } + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + InstancePtr->Flags &= ~FLAG_PHY_UP; + break; + + /* For physical layer up */ + case EVENT_PHYUP: + InstancePtr->Flags |= FLAG_PHY_UP; + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "unauthenticated" state of the receiver state machine. +* +* @param InstancePtr is the receiver instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunUnauthenticatedState(XHdcp1x_Rx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For authenticate */ + case EVENT_AUTHENTICATE: + *NextStatePtr = STATE_COMPUTATIONS; + break; + + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "computations" state of the receiver state machine. +* +* @param InstancePtr is the receiver instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunComputationsState(XHdcp1x_Rx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For authenticate */ + case EVENT_AUTHENTICATE: + StartComputations(InstancePtr, NextStatePtr); + break; + + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* For poll */ + case EVENT_POLL: + PollForComputations(InstancePtr, NextStatePtr); + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "authenticated" state of the receiver state machine. +* +* @param InstancePtr is the receiver instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunAuthenticatedState(XHdcp1x_Rx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For authenticate */ + case EVENT_AUTHENTICATE: + *NextStatePtr = STATE_COMPUTATIONS; + break; + + /* For check */ + case EVENT_CHECK: + CheckLinkIntegrity(InstancePtr, NextStatePtr); + break; + + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* For update Ri */ + case EVENT_UPDATERi: + UpdateRi(InstancePtr, NextStatePtr); + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "link integrity failed" state of the receiver state +* machine. +* +* @param InstancePtr is the receiver instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunLinkIntegrityFailedState(XHdcp1x_Rx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For authenticate */ + case EVENT_AUTHENTICATE: + *NextStatePtr = STATE_COMPUTATIONS; + break; + + /* For check */ + case EVENT_CHECK: + CheckLinkIntegrity(InstancePtr, NextStatePtr); + break; + + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "physical layer down" state of the receiver state +* machine. +* +* @param InstancePtr is the receiver instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunPhysicalLayerDownState(XHdcp1x_Rx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer up */ + case EVENT_PHYUP: + *NextStatePtr = STATE_UNAUTHENTICATED; + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function enters a HDCP receiver state. +* +* @param InstancePtr is the receiver instance. +* @param State is the state to enter. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void EnterState(XHdcp1x_Rx *InstancePtr, tState State, + tState *NextStatePtr) +{ + /* Which state? */ + switch (State) { + /* For the disabled state */ + case STATE_DISABLED: + Disable(InstancePtr); + break; + + /* For the unauthenticated state */ + case STATE_UNAUTHENTICATED: + InstancePtr->Flags |= FLAG_PHY_UP; + break; + + /* For the computations state */ + case STATE_COMPUTATIONS: + StartComputations(InstancePtr, NextStatePtr); + break; + + /* For the authenticated state */ + case STATE_AUTHENTICATED: + DebugLog(InstancePtr, "authenticated"); + SetCheckLinkState(InstancePtr, TRUE); + break; + + /* For the link integrity failed state */ + case STATE_LINKINTEGRITYFAILED: + InstancePtr->Stats.LinkFailures++; + ReportLinkIntegrityFailure(InstancePtr, NextStatePtr); + break; + + /* For physical layer down */ + case STATE_PHYDOWN: + InstancePtr->Flags &= ~FLAG_PHY_UP; + XHdcp1x_CipherDisable(&(InstancePtr->Cipher)); + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function exits a HDCP receiver state. +* +* @param InstancePtr is the receiver instance. +* @param State is the state to exit. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void ExitState(XHdcp1x_Rx *InstancePtr, tState State) +{ + /* Which state? */ + switch (State) { + /* For the disabled state */ + case STATE_DISABLED: + Enable(InstancePtr); + break; + + /* For the authenticated state */ + case STATE_AUTHENTICATED: + SetCheckLinkState(InstancePtr, FALSE); + break; + + /* For physical layer down */ + case STATE_PHYDOWN: + XHdcp1x_CipherEnable(&(InstancePtr->Cipher)); + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function drives a HDCP receiver state machine. +* +* @param InstancePtr is the receiver instance. +* @param Event is the event to process. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void DoTheState(XHdcp1x_Rx *InstancePtr, tEvent Event) +{ + tState NextState = InstancePtr->CurrentState; + + /* Which state? */ + switch (InstancePtr->CurrentState) { + /* For the disabled state */ + case STATE_DISABLED: + RunDisabledState(InstancePtr, Event, &NextState); + break; + + /* For the unauthenticated state */ + case STATE_UNAUTHENTICATED: + RunUnauthenticatedState(InstancePtr, Event, &NextState); + break; + + /* For the computations state */ + case STATE_COMPUTATIONS: + RunComputationsState(InstancePtr, Event, &NextState); + break; + + /* For the authenticated state */ + case STATE_AUTHENTICATED: + RunAuthenticatedState(InstancePtr, Event, &NextState); + break; + + /* For the link integrity failed state */ + case STATE_LINKINTEGRITYFAILED: + RunLinkIntegrityFailedState(InstancePtr, Event, + &NextState); + break; + + /* For the physical layer down state */ + case STATE_PHYDOWN: + RunPhysicalLayerDownState(InstancePtr, Event, + &NextState); + break; + + /* Otherwise */ + default: + break; + } + + /* Check for state change */ + while (InstancePtr->CurrentState != NextState) { + /* Perform the state transition */ + ExitState(InstancePtr, InstancePtr->CurrentState); + InstancePtr->PreviousState = InstancePtr->CurrentState; + InstancePtr->CurrentState = NextState; + EnterState(InstancePtr, InstancePtr->CurrentState, &NextState); + } +} + +/*****************************************************************************/ +/** +* This function initializes a HDCP receiver state machine. +* +* @param InstancePtr is the receiver instance. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void Init(XHdcp1x_Rx *InstancePtr) +{ + tState DummyState = STATE_DISABLED; + + /* Update theHandler */ + InstancePtr->PendingEvents = 0; + + /* Kick the state machine */ + EnterState(InstancePtr, STATE_DISABLED, &DummyState); +} + +/*****************************************************************************/ +/** +* This function processes the events pending on a state machine. +* +* @param InstancePtr is the receiver instance. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void ProcessPending(XHdcp1x_Rx *InstancePtr) +{ + /* Check for any pending events */ + if (InstancePtr->PendingEvents != 0) { + u16 Pending = InstancePtr->PendingEvents; + tEvent Event = EVENT_NULL; + + /* Update InstancePtr */ + InstancePtr->PendingEvents = 0; + + /* Iterate through thePending */ + do { + /* Check for a pending event */ + if ((Pending & 1u) != 0) { + DoTheState(InstancePtr, Event); + } + + /* Update for loop */ + Pending >>= 1; + Event++; + } + while (Pending != 0); + } +} + +/*****************************************************************************/ +/** +* This function converts from a state to a display string. +* +* @param State is the state to convert. +* +* @return The corresponding display string. +* +* @note None. +* +******************************************************************************/ +static const char *StateToString(tState State) +{ + const char *String = NULL; + + /* Which state? */ + switch (State) { + case STATE_DISABLED: + String = "disabled"; + break; + + case STATE_UNAUTHENTICATED: + String = "unauthenticated"; + break; + + case STATE_COMPUTATIONS: + String = "computations"; + break; + + case STATE_AUTHENTICATED: + String = "authenticated"; + break; + + case STATE_LINKINTEGRITYFAILED: + String = "link-integrity-failed"; + break; + + case STATE_PHYDOWN: + String = "physical-layer-down"; + break; + + default: + String = "???"; + break; + } + + return (String); +} diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_rx.h b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_rx.h index 5dc9da20..410cf5d3 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_rx.h +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_rx.h @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -41,10 +41,11 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ + #ifndef XHDCP1X_RX_H /**< Prevent circular inclusions by using protection macros */ #define XHDCP1X_RX_H @@ -54,6 +55,7 @@ extern "C" { #endif /***************************** Include Files *********************************/ + #include "xhdcp1x.h" #include "xparameters.h" #include "xstatus.h" @@ -66,8 +68,9 @@ extern "C" { /***************** Macros (Inline Functions) Definitions *********************/ /************************** Function Prototypes ******************************/ + int XHdcp1x_RxCfgInitialize(XHdcp1x_Rx *InstancePtr, - const XHdcp1x_Config *CfgPtr, void* PhyIfPtr); + const XHdcp1x_Config *CfgPtr, void *PhyIfPtr); int XHdcp1x_RxPoll(XHdcp1x_Rx *InstancePtr); diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_selftest.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_selftest.c index 82b12a72..13db9fc0 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_selftest.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_selftest.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -29,7 +29,6 @@ * this Software without prior written authorization from Xilinx. * ******************************************************************************/ - /*****************************************************************************/ /** * @@ -42,13 +41,13 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. -* 1.01 07/23/15 Additional documentation and formating +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ /***************************** Include Files *********************************/ + #include #include #include "xhdcp1x.h" @@ -72,15 +71,15 @@ /*****************************************************************************/ /** * -* This function self tests an hdcp interface +* This function self tests an hdcp interface. * -* @param InstancePtr the interface to test +* @param InstancePtr is the interface to test. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. +* - XST_FAILURE otherwise. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_SelfTest(XHdcp1x *InstancePtr) diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_sinit.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_sinit.c index ba1f8a6c..600eeecc 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_sinit.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_sinit.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -41,13 +41,13 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. -* 1.01 07/23/15 Additional documentation and formating +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ /***************************** Include Files *********************************/ + #include "xhdcp1x.h" #include "xhdcp1x_cipher.h" #include "xparameters.h" @@ -61,29 +61,27 @@ /************************** Function Prototypes ******************************/ /************************** Variable Definitions *****************************/ + extern XHdcp1x_Config XHdcp1x_ConfigTable[]; /************************** Function Definitions *****************************/ /*****************************************************************************/ /** -* * This function returns a reference to an XHdcp1x_Config structure based on * specified device ID. * -* @param DeviceID the unique core ID of the HDCP interface +* @param DeviceID is the unique core ID of the HDCP interface. * -* @return -* A reference to the config record in the configuration table (in xhdcp_g.c) -* corresponding the specified DeviceID. NULL if no match is found. +* @return A reference to the config record in the configuration table (in +* xhdcp_g.c) corresponding the specified DeviceID. NULL if no +* match is found. * -* @note -* None. +* @note None. * ******************************************************************************/ XHdcp1x_Config *XHdcp1x_LookupConfig(u16 DeviceID) { - /* Locals */ XHdcp1x_Config *OneToCheck = XHdcp1x_ConfigTable; XHdcp1x_Config *CfgPtr = NULL; u32 NumLeft = XPAR_XHDCP_NUM_INSTANCES; @@ -91,18 +89,19 @@ XHdcp1x_Config *XHdcp1x_LookupConfig(u16 DeviceID) /* Iterate through the configuration table */ do { /* Is this the one? */ - if (OneToCheck->DeviceId == DeviceID) + if (OneToCheck->DeviceId == DeviceID) { CfgPtr = OneToCheck; + } /* Update for loop */ OneToCheck++; NumLeft--; - } while ((NumLeft > 0) && (CfgPtr == NULL)); + } + while ((NumLeft > 0) && (CfgPtr == NULL)); /* Sanity Check */ if (CfgPtr != 0) { - u32 Value = 0; u32 BaseAddress = CfgPtr->BaseAddress; @@ -127,6 +126,5 @@ XHdcp1x_Config *XHdcp1x_LookupConfig(u16 DeviceID) } } - /* Return */ return (CfgPtr); } diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_tx.c b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_tx.c index 0fa80e59..8ffc5efc 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_tx.c +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_tx.c @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -42,15 +42,14 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. -* 1.01 07/23/15 Additional documentation and formating +* 1.00 fidus 07/16/15 Initial release. * * *****************************************************************************/ /***************************** Include Files *********************************/ -#include "xparameters.h" +#include "xparameters.h" #include "sha1.h" #include #include @@ -61,14 +60,15 @@ #include "xhdcp1x_platform.h" #include "xhdcp1x_port.h" #if defined(XPAR_XHDMI_TX_NUM_INSTANCES) && (XPAR_XHDMI_TX_NUM_INSTANCES > 0) - #include "xhdcp1x_port_hdmi.h" +#include "xhdcp1x_port_hdmi.h" #else - #include "xhdcp1x_port_dp.h" +#include "xhdcp1x_port_dp.h" #endif #include "xhdcp1x_tx.h" #include "xil_types.h" /************************** Constant Definitions *****************************/ + #define FLAG_PHY_UP (1u << 0) /**< Flag to track physical state */ #define FLAG_IS_REPEATER (1u << 1) /**< Flag to track repeater state */ @@ -77,8 +77,8 @@ #define TMO_1SECOND (1000u) /**< Timeout value for 1s */ /**************************** Type Definitions *******************************/ -typedef enum -{ + +typedef enum { EVENT_NULL, EVENT_AUTHENTICATE, EVENT_CHECK, @@ -89,11 +89,9 @@ typedef enum EVENT_PHYUP, EVENT_POLL, EVENT_TIMEOUT, - } tEvent; -typedef enum -{ +typedef enum { STATE_DISABLED, STATE_DETERMINERXCAPABLE, STATE_EXCHANGEKSVS, @@ -106,2072 +104,113 @@ typedef enum STATE_READKSVLIST, STATE_UNAUTHENTICATED, STATE_PHYDOWN, - } tState; /***************** Macros (Inline Functions) Definitions *********************/ /*****************************************************************************/ /** +* This queries an interface to determine if it is Display Port (DP). * -* This queries an interface to determine if it is Display Port (DP) +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating DP (TRUE) or not (FALSE). * -* @return -* Truth value indicating DP (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ #define IsDP(InstancePtr) (!InstancePtr->CfgPtr->IsHDMI) /*****************************************************************************/ /** +* This queries an interface to determine if it is HDMI. * -* This queries an interface to determine if it is HDMI +* @param InstancePtr is the instance to query. * -* @param InstancePtr the instance to query +* @return Truth value indicating HDMI (TRUE) or not (FALSE). * -* @return -* Truth value indicating HDMI (TRUE) or not (FALSE) -* -* @note -* None. +* @note None. * ******************************************************************************/ #define IsHDMI(InstancePtr) (InstancePtr->CfgPtr->IsHDMI) +/*************************** Function Prototypes *****************************/ + +static void DebugLog(const XHdcp1x_Tx *InstancePtr, const char *LogMsg); +static void PostEvent(XHdcp1x_Tx *InstancePtr, tEvent Event); +static void StartTimer(XHdcp1x_Tx *InstancePtr, u16 TimeoutInMs); +static void StopTimer(XHdcp1x_Tx *InstancePtr); +static void BusyDelay(XHdcp1x_Tx *InstancePtr, u16 DelayInMs); +static void ReauthenticateCallback(void *Parameter); +static void CheckLinkCallback(void *Parameter); +static void SetCheckLinkState(XHdcp1x_Tx *InstancePtr, int IsEnabled); +static void EnableEncryption(XHdcp1x_Tx *InstancePtr); +static void DisableEncryption(XHdcp1x_Tx *InstancePtr); +static void Enable(XHdcp1x_Tx *InstancePtr); +static void Disable(XHdcp1x_Tx *InstancePtr); +static void CheckRxCapable(const XHdcp1x_Tx *InstancePtr, tState *NextStatePtr); +static u64 GenerateAn(XHdcp1x_Tx *InstancePtr); +static int IsKsvValid(u64 Ksv); +static void ExchangeKsvs(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr); +static void StartComputations(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr); +static void PollForComputations(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr); +static void ValidateRx(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr); +static void CheckLinkIntegrity(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr); +static void TestForRepeater(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr); +static void PollForWaitForReady(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr); +static int ValidateKsvList(XHdcp1x_Tx *InstancePtr, u16 RepeaterInfo); +static void ReadKsvList(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr); +static int IsAuthenticated(const XHdcp1x_Tx *InstancePtr); +static void RunDisabledState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunDetermineRxCapableState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunExchangeKsvsState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunComputationsState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunValidateRxState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunAuthenticatedState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunLinkIntegrityCheckState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunTestForRepeaterState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunWaitForReadyState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunReadKsvListState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunUnauthenticatedState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void RunPhysicalLayerDownState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr); +static void EnterState(XHdcp1x_Tx *InstancePtr, tState State, + tState *NextStatePtr); +static void ExitState(XHdcp1x_Tx *InstancePtr, tState State); +static void DoTheState(XHdcp1x_Tx *InstancePtr, tEvent Event); +static void Init(XHdcp1x_Tx *InstancePtr); +static void ProcessPending(XHdcp1x_Tx *InstancePtr); +static const char *StateToString(tState State); + /************************** Function Definitions *****************************/ /*****************************************************************************/ /** +* This function initializes an HDCP interface. * -* This function logs a debug message on behalf of a handler state machine -* -* @param InstancePtr the receiver instance -* @param LogMsg the message to log +* @param InstancePtr is the transmitter instance. +* @param CfgPtr is the configuration of the instance. +* @param PhyIfPtr is pointer to the underlying physical interface. * * @return -* void +* - XST_SUCCESS if successful. * -* @note -* None. -* -******************************************************************************/ -static void DebugLog(const XHdcp1x_Tx *InstancePtr, const char *LogMsg) -{ - char Label[16]; - - /* Format Label */ - snprintf(Label, 16, "hdcp-tx(%d) - ", InstancePtr->CfgPtr->DeviceId); - - /* Log it */ - XHDCP1X_DEBUG_LOGMSG(Label); - XHDCP1X_DEBUG_LOGMSG(LogMsg); - XHDCP1X_DEBUG_LOGMSG("\r\n"); - - return; -} - -/*****************************************************************************/ -/** -* -* This function posts an event to a state machine -* -* @param InstancePtr the receiver instance -* @param Event the event to post -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void PostEvent(XHdcp1x_Tx *InstancePtr, tEvent Event) -{ - /* Check for disable and clear any pending enable */ - if (Event == EVENT_DISABLE) { - InstancePtr->PendingEvents &= ~(1u << EVENT_ENABLE); - } - /* Check for phy-down and clear any pending phy-up */ - else if (Event == EVENT_PHYDOWN) { - InstancePtr->PendingEvents &= ~(1u << EVENT_PHYUP); - } - - /* Post it */ - InstancePtr->PendingEvents |= (1u << Event); - - return; -} - -/*****************************************************************************/ -/** -* -* This function starts a state machine's timer -* -* @param InstancePtr the state machine -* @param TimeoutInMs the timeout in milli-seconds -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void StartTimer(XHdcp1x_Tx* InstancePtr, u16 TimeoutInMs) -{ - /* Start it */ - XHdcp1x_PlatformTimerStart((XHdcp1x*) InstancePtr, TimeoutInMs); - - return; -} - -/*****************************************************************************/ -/** -* -* This function stops a state machine's timer -* -* @param InstancePtr the state machine -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void StopTimer(XHdcp1x_Tx* InstancePtr) -{ - /* Stop it */ - XHdcp1x_PlatformTimerStop((XHdcp1x*) InstancePtr); - - return; -} - -/*****************************************************************************/ -/** -* -* This function busy delays a state machine -* -* @param InstancePtr the state machine -* @param TimeoutInMs the delay time in milli-seconds -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void BusyDelay(XHdcp1x_Tx* InstancePtr, u16 DelayInMs) -{ - /* Busy wait */ - XHdcp1x_PlatformTimerBusy((XHdcp1x*) InstancePtr, DelayInMs); - - return; -} - -/*****************************************************************************/ -/** -* -* This function acts as the reauthentication callback for a state machine -* -* @param Parameter the parameter specified during registration -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void ReauthenticateCallback(void* Parameter) -{ - /* Locals */ - XHdcp1x_Tx* InstancePtr = Parameter; - - /* Update statistics */ - InstancePtr->Stats.ReauthRequested++; - - /* Post the re-authentication request */ - PostEvent(InstancePtr, EVENT_AUTHENTICATE); - - return; -} - -/*****************************************************************************/ -/** -* -* This function acts as the check link callback for a state machine -* -* @param Parameter the parameter specified during registration -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void CheckLinkCallback(void* Parameter) -{ - /* Locals */ - XHdcp1x_Tx* InstancePtr = Parameter; - - /* Post the check request */ - PostEvent(InstancePtr, EVENT_CHECK); - - return; -} - -/*****************************************************************************/ -/** -* -* This function sets the check link state of the handler -* -* @param InstancePtr the hdcp state machine -* @param isEnabled truth value indicating on/off -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void SetCheckLinkState(XHdcp1x_Tx* InstancePtr, int isEnabled) -{ - /* Check for HDMI */ - if (IsHDMI(InstancePtr)) - { - XHdcp1x_Cipher *CipherPtr = &(InstancePtr->Cipher); - - /* Check for enabled */ - if (isEnabled) - { - /* Register Callback */ - XHdcp1x_CipherSetCallback(CipherPtr, - XHDCP1X_CIPHER_HANDLER_Ri_UPDATE, - &CheckLinkCallback, InstancePtr); - - /* Enable it */ - XHdcp1x_CipherSetRiUpdate(CipherPtr, TRUE); - } - /* Otherwise */ - else - { - /* Disable it */ - XHdcp1x_CipherSetRiUpdate(CipherPtr, FALSE); - } - } - - /* Return */ - return; -} - -/*****************************************************************************/ -/** -* -* This function enables encryption for a state machine -* -* @param InstancePtr the hdcp state machine -* -* @return -* void -* -* @note -* This function inserts a 5ms delay for things to settle when encryption -* is actually being disabled -* -******************************************************************************/ -static void EnableEncryption(XHdcp1x_Tx* InstancePtr) -{ - /* Check for encryption enabled */ - if (InstancePtr->EncryptionMap != 0) { - - u64 StreamMap = 0; - - /* Determine StreamMap */ - StreamMap = XHdcp1x_CipherGetEncryption(&InstancePtr->Cipher); - - /* Check if there is something to do */ - if (StreamMap != InstancePtr->EncryptionMap) { - - /* Wait a bit */ - BusyDelay(InstancePtr, TMO_5MS); - - /* Enable it */ - XHdcp1x_CipherEnableEncryption(&InstancePtr->Cipher, - InstancePtr->EncryptionMap); - } - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function disables encryption for a state machine -* -* @param InstancePtr the hdcp state machine -* -* @return -* void -* -* @note -* This function inserts a 5ms delay for things to settle when encryption -* is actually being disabled -* -******************************************************************************/ -static void DisableEncryption(XHdcp1x_Tx* InstancePtr) -{ - /* Locals */ - u64 StreamMap = XHdcp1x_CipherGetEncryption(&InstancePtr->Cipher); - - /* Check if encryption actually enabled */ - if (StreamMap != 0) { - - /* Update StreamMap for all stream */ - StreamMap = (u64) (-1); - - /* Disable it all */ - XHdcp1x_CipherDisableEncryption(&InstancePtr->Cipher, - StreamMap); - - /* Wait at least a frame */ - BusyDelay(InstancePtr, TMO_5MS); - } - - /* Return */ - return; -} - -/*****************************************************************************/ -/** -* -* This function enables a state machine -* -* @param InstancePtr the hdcp state machine -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void Enable(XHdcp1x_Tx *InstancePtr) -{ - /* Clear statistics */ - memset(&(InstancePtr->Stats), 0, sizeof(InstancePtr->Stats)); - - /* Enable the crypto engine */ - XHdcp1x_CipherEnable(&InstancePtr->Cipher); - - /* Register the re-authentication callback */ - XHdcp1x_PortSetCallback(&InstancePtr->Port, - XHDCP1X_PORT_HANDLER_AUTHENTICATE, - &ReauthenticateCallback, InstancePtr); - - /* Enable the hdcp port */ - XHdcp1x_PortEnable(&InstancePtr->Port); - - return; -} - -/*****************************************************************************/ -/** -* -* This function disables a state machine -* -* @param InstancePtr the hdcp state machine -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void Disable(XHdcp1x_Tx* InstancePtr) -{ - /* Disable the hdcp port */ - XHdcp1x_PortDisable(&InstancePtr->Port); - - /* Disable the cryto engine */ - XHdcp1x_CipherDisable(&InstancePtr->Cipher); - - /* Disable the timer */ - StopTimer(InstancePtr); - - /* Update InstancePtr */ - InstancePtr->Flags &= ~FLAG_IS_REPEATER; - InstancePtr->StateHelper = 0; - InstancePtr->EncryptionMap = 0; - - /* Return */ - return; -} - -/*****************************************************************************/ -/** -* -* This function checks to ensure that the remote end is hdcp capable -* -* @param InstancePtr the hdcp state machine -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void CheckRxCapable(const XHdcp1x_Tx* InstancePtr, tState *NextStatePtr) -{ - /* Check for capable */ - if (XHdcp1x_PortIsCapable(&InstancePtr->Port)) { - - /* Log */ - DebugLog(InstancePtr, "rx hdcp capable"); - - /* Update NextStatePtr */ - *NextStatePtr = STATE_EXCHANGEKSVS; - } - else { - - /* Log */ - DebugLog(InstancePtr, "rx not capable"); - - /* Update NextStatePtr */ - *NextStatePtr = STATE_UNAUTHENTICATED; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function generates the An from a random number generator -* -* @param InstancePtr the hdcp state machine -* -* @return -* A 64-bit psuedo random number (An) -* -* @note -* None. -* -******************************************************************************/ -static u64 GenerateAn(XHdcp1x_Tx* InstancePtr) -{ - XHdcp1x_Cipher *CipherPtr = &InstancePtr->Cipher; - u64 An = 0; - - /* Attempt to generate An */ - if (XHdcp1x_CipherDoRequest(CipherPtr, XHDCP1X_CIPHER_REQUEST_RNG) == - XST_SUCCESS) { - - /* Wait until done */ - while (!XHdcp1x_CipherIsRequestComplete(CipherPtr)); - - /* Update theAn */ - An = XHdcp1x_CipherGetMi(CipherPtr); - } - - /* Check if zero */ - if (An == 0) { - An = 0x351F7175406A74Dull; - } - - return (An); -} - -/*****************************************************************************/ -/** -* -* This function validates a KSV value as having 20 1s and 20 0s -* -* @param Ksv the value to validate -* -* @return -* Truth value indicating valid (TRUE) or not (FALSE) -* -* @note -* None. -* -******************************************************************************/ -static int IsKsvValid(u64 Ksv) -{ - int IsValid = FALSE; - int NumOnes = 0; - - /* Determine NumOnes */ - while (Ksv != 0) { - if ((Ksv & 1) != 0) - NumOnes++; - Ksv >>= 1; - } - - /* Check for 20 1s */ - if (NumOnes == 20) - IsValid = TRUE; - - return (IsValid); -} - -/*****************************************************************************/ -/** -* -* This function exchanges the ksvs between the two ends of the link -* -* @param InstancePtr the hdcp state machine -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void ExchangeKsvs(XHdcp1x_Tx* InstancePtr, tState* NextStatePtr) -{ - /* Locals */ - XHdcp1x_Port *PortPtr = &InstancePtr->Port; - XHdcp1x_Cipher *CipherPtr = &InstancePtr->Cipher; - u8 Buf[8]; - - /* Initialize Buf */ - memset(Buf, 0, 8); - - /* Update NextStatePtr - assume failure */ - *NextStatePtr = STATE_UNAUTHENTICATED; - - /* Read the Bksv from remote end */ - if (XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_BKSV, Buf, 5) > 0) - { - u64 RemoteKsv = 0; - - /* Determine theRemoteKsv */ - XHDCP1X_PORT_BUF_TO_UINT(RemoteKsv, Buf, - XHDCP1X_PORT_SIZE_BKSV*8); - - /* Check for invalid */ - if (!IsKsvValid(RemoteKsv)) { - DebugLog(InstancePtr, "Bksv invalid"); - } - /* Check for revoked */ - else if (XHdcp1x_PlatformIsKsvRevoked((XHdcp1x*) InstancePtr, - RemoteKsv)) { - DebugLog(InstancePtr, "Bksv is revoked"); - } - /* Otherwise we're good to go */ - else { - u64 LocalKsv = 0; - u64 An = 0; - - /* Check for repeater and update InstancePtr */ - if (XHdcp1x_PortIsRepeater(&InstancePtr->Port)) { - InstancePtr->Flags |= FLAG_IS_REPEATER; - } - else { - InstancePtr->Flags &= ~FLAG_IS_REPEATER; - } - - /* Generate theAn */ - An = GenerateAn(InstancePtr); - - /* Save theAn into the state helper for use later */ - InstancePtr->StateHelper = An; - - /* Determine theLocalKsv */ - LocalKsv = XHdcp1x_CipherGetLocalKsv(CipherPtr); - - /* Load the cipher with the remote ksv */ - XHdcp1x_CipherSetRemoteKsv(CipherPtr, RemoteKsv); - - /* Send An to remote */ - XHDCP1X_PORT_UINT_TO_BUF(Buf, An, - XHDCP1X_PORT_SIZE_AN*8); - XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_AN, Buf, - XHDCP1X_PORT_SIZE_AN); - - /* Send AKsv to remote */ - XHDCP1X_PORT_UINT_TO_BUF(Buf, LocalKsv, - XHDCP1X_PORT_SIZE_AKSV*8); - XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_AKSV, - Buf, XHDCP1X_PORT_SIZE_AKSV); - - /* Update NextStatePtr */ - *NextStatePtr = STATE_COMPUTATIONS; - } - } - /* Otherwise */ - else { - /* Update the statistics */ - InstancePtr->Stats.ReadFailures++; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function initiates the computations for a state machine -* -* @param InstancePtr the hdcp receiver state machine -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void StartComputations(XHdcp1x_Tx* InstancePtr, tState* NextStatePtr) -{ - /* Locals */ - XHdcp1x_Cipher *CipherPtr = &InstancePtr->Cipher; - u64 Value = 0; - u32 X = 0; - u32 Y = 0; - u32 Z = 0; - - /* Log */ - DebugLog(InstancePtr, "starting computations"); - - /* Update Value with An */ - Value = InstancePtr->StateHelper; - - /* Load the cipher B registers with An */ - X = (u32) (Value & 0x0FFFFFFFul); - Value >>= 28; - Y = (u32) (Value & 0x0FFFFFFFul); - Value >>= 28; - Z = (u32) (Value & 0x000000FFul); - if ((InstancePtr->Flags & FLAG_IS_REPEATER) != 0) { - Z |= (1ul << 8); - } - XHdcp1x_CipherSetB(CipherPtr, X, Y, Z); - - /* Initiate the block cipher */ - XHdcp1x_CipherDoRequest(CipherPtr, XHDCP1X_CIPHER_REQUEST_BLOCK); - - /* Return */ - return; -} - -/*****************************************************************************/ -/** -* -* This function polls the progress of the computations for a state machine -* -* @param InstancePtr the hdcp state machine -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void PollForComputations(XHdcp1x_Tx* InstancePtr, tState* NextStatePtr) -{ - /* Check for done */ - if (XHdcp1x_CipherIsRequestComplete(&InstancePtr->Cipher)) { - DebugLog(InstancePtr, "computations complete"); - *NextStatePtr = STATE_VALIDATERX; - } - else { - DebugLog(InstancePtr, "waiting for computations"); - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function validates the attached receiver -* -* @param InstancePtr the hdcp state machine -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void ValidateRx(XHdcp1x_Tx* InstancePtr, tState* NextStatePtr) -{ - XHdcp1x_Port *PortPtr = &InstancePtr->Port; - XHdcp1x_Cipher *CipherPtr = &InstancePtr->Cipher; - u8 Buf[2]; - int NumTries = 3; - - /* Update NextStatePtr */ - *NextStatePtr = STATE_UNAUTHENTICATED; - - /* Attempt to read Ro */ - do { - /* Read the remote Ro' */ - if (XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_RO, - Buf, 2) > 0) { - - char LogBuf[32]; - u16 RemoteRo = 0; - u16 LocalRo = 0; - - /* Determine RemoteRo */ - XHDCP1X_PORT_BUF_TO_UINT(RemoteRo, Buf, 2*8); - - /* Determine theLLocalRoocalRo */ - LocalRo = XHdcp1x_CipherGetRo(CipherPtr); - - /* Compare the Ro values */ - if (LocalRo == RemoteRo) { - - /* Determine theLogBuf */ - snprintf(LogBuf, 32, "rx valid Ro/Ro' (%04X)", - LocalRo); - - /* Update NextStatePtr */ - *NextStatePtr = STATE_TESTFORREPEATER; - } - /* Otherwise */ - else { - /* Determine theLogBuf */ - snprintf(LogBuf, 32, "Ro/Ro' mismatch (%04X/" - "%04X)", LocalRo, RemoteRo); - - /* Update statistics if the last attempt */ - if (NumTries == 1) - InstancePtr->Stats.AuthFailed++; - } - - /* Log */ - DebugLog(InstancePtr, LogBuf); - } - /* Otherwise */ - else { - - /* Log */ - DebugLog(InstancePtr, "Ro' read failure"); - - /* Update the statistics */ - InstancePtr->Stats.ReadFailures++; - } - - /* Update for loop */ - NumTries--; - } - while ((*NextStatePtr == STATE_UNAUTHENTICATED) && (NumTries > 0)); - - return; -} - -/*****************************************************************************/ -/** -* -* This function checks the integrity of a hdcp link -* -* @param InstancePtr the hdcp state machine -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void CheckLinkIntegrity(XHdcp1x_Tx* InstancePtr, tState* NextStatePtr) -{ - XHdcp1x_Port *PortPtr = &InstancePtr->Port; - XHdcp1x_Cipher *CipherPtr = &InstancePtr->Cipher; - u8 Buf[2]; - int NumTries = 3; - - /* Update theNextState */ - *NextStatePtr = STATE_DETERMINERXCAPABLE; - - /* Iterate through the tries */ - do - { - /* Read the remote Ri' */ - if (XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_RO, - Buf, 2) > 0) { - - char LogBuf[48]; - u16 RemoteRi = 0; - u16 LocalRi = 0; - - /* Determine theRemoteRo */ - XHDCP1X_PORT_BUF_TO_UINT(RemoteRi, Buf, 16); - - /* Determine theLocalRi */ - LocalRi = XHdcp1x_CipherGetRi(CipherPtr); - - /* Compare the local and remote values */ - if (LocalRi == RemoteRi) { - *NextStatePtr = STATE_AUTHENTICATED; - snprintf(LogBuf, 48, "link check passed Ri/Ri'" - "(%04X)", LocalRi); - } - /* Check for last attempt */ - else if (NumTries == 1) { - snprintf(LogBuf, 48, "link check failed Ri/Ri'" - "(%04X/%04X)", LocalRi, - RemoteRi); - } - - /* Log */ - DebugLog(InstancePtr, LogBuf); - } - else { - DebugLog(InstancePtr, "Ri' read failure"); - InstancePtr->Stats.ReadFailures++; - } - - /* Update for loop */ - NumTries--; - } - while ((*NextStatePtr != STATE_AUTHENTICATED) && (NumTries > 0)); - - /* Check for success */ - if (*NextStatePtr == STATE_AUTHENTICATED) { - InstancePtr->Stats.LinkCheckPassed++; - } - else { - InstancePtr->Stats.LinkCheckFailed++; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function checks the remote end to see if its a repeater -* -* @param InstancePtr the hdcp state machine -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* The implementation of this function enables encryption when a repeater is -* detected downstream. The standard is ambiguous as to the handling of this -* specific case by this behaviour is required in order to pass the Unigraf -* compliance test suite. -* -******************************************************************************/ -static void TestForRepeater(XHdcp1x_Tx *InstancePtr, tState* NextStatePtr) -{ - XHdcp1x_Port *PortPtr = &InstancePtr->Port; - - /* Check for repeater */ - if (XHdcp1x_PortIsRepeater(PortPtr)) { - - u8 Buf[XHDCP1X_PORT_SIZE_AINFO]; - - /* Update InstancePtr */ - InstancePtr->Flags |= FLAG_IS_REPEATER; - - /* Clear AINFO */ - memset(Buf, 0, XHDCP1X_PORT_SIZE_AINFO); - XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_AINFO, Buf, - XHDCP1X_PORT_SIZE_AINFO); - - /* Update NextStatePtr */ - *NextStatePtr = STATE_WAITFORREADY; - - /* Log */ - DebugLog(InstancePtr, "repeater detected"); - - /* Enable authentication if needed */ - EnableEncryption(InstancePtr); - } - else { - /* Update InstancePtr */ - InstancePtr->Flags &= ~FLAG_IS_REPEATER; - - /* Update NextStatePtr */ - *NextStatePtr = STATE_AUTHENTICATED; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function polls a state machine in the "wait for ready" state -* -* @param InstancePtr the hdcp state machine -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void PollForWaitForReady(XHdcp1x_Tx *InstancePtr, tState* NextStatePtr) -{ - /* Locals */ - XHdcp1x_Port *PortPtr = &InstancePtr->Port; - u16 RepeaterInfo = 0; - int Status = XST_SUCCESS; - - /* Attempt to read the repeater info */ - Status = XHdcp1x_PortGetRepeaterInfo(PortPtr, &RepeaterInfo); - if (Status == XST_SUCCESS) { - /* Check that neither cascade or device numbers exceeded */ - if ((RepeaterInfo & 0x0880u) == 0) { - /* Check for at least one attached device */ - if ((RepeaterInfo & 0x007Fu) != 0) { - /* Update InstancePtr */ - InstancePtr->StateHelper = RepeaterInfo; - - /* Update NextStatePtr */ - *NextStatePtr = STATE_READKSVLIST; - - /* Log */ - DebugLog(InstancePtr, "devices attached: " - "ksv list ready"); - } - /* Otherwise */ - else { - /* Update NextStatePtr */ - *NextStatePtr = STATE_AUTHENTICATED; - - /* Log */ - DebugLog(InstancePtr, "no attached devices"); - } - } - /* Check for cascade exceeded */ - else { - /* Update NextStatePtr */ - *NextStatePtr = STATE_UNAUTHENTICATED; - - /* Log */ - if ((RepeaterInfo & 0x0800u) != 0) { - DebugLog(InstancePtr, "max cascade exceeded"); - } - else { - DebugLog(InstancePtr, "max devices exceeded"); - } - } - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function validates the ksv list from an attached repeater -* -* @param InstancePtr the hdcp state machine -* @param RepeaterInfo the repeater information -* -* @return -* Truth value indicating valid (TRUE) or invalid (FALSE) -* -* @note -* None. -* -******************************************************************************/ -static int ValidateKsvList(XHdcp1x_Tx* InstancePtr, u16 RepeaterInfo) -{ - XHdcp1x_Port *PortPtr = &InstancePtr->Port; - XHdcp1x_Cipher *CipherPtr = &InstancePtr->Cipher; - SHA1Context Sha1Context; - u8 Buf[24]; - int NumToRead = 0; - int IsValid = FALSE; - - /* Initialize Buf */ - memset(Buf, 0, 24); - - /* Initialize Sha1Context */ - SHA1Reset(&Sha1Context); - - /* Assume success */ - IsValid = TRUE; - - /* Determine theNumToRead */ - NumToRead = ((RepeaterInfo & 0x7Fu)*5); - - /* Read the ksv list */ - do { - int NumThisTime = XHDCP1X_PORT_SIZE_KSVFIFO; - - /* Truncate if necessary */ - if (NumThisTime > NumToRead) - NumThisTime = NumToRead; - - /* Read the next chunk of the list */ - if (XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_KSVFIFO, - Buf, NumThisTime) > 0) { - /* Update the calculation of V */ - SHA1Input(&Sha1Context, Buf, NumThisTime); - } - else { - /* Update the statistics */ - InstancePtr->Stats.ReadFailures++; - - /* Update isValid */ - IsValid = FALSE; - } - - /* Update for loop */ - NumToRead -= NumThisTime; - } - while ((NumToRead > 0) && (IsValid)); - - /* Check for success */ - if (IsValid) { - u64 Mo = 0; - u8 Sha1Result[SHA1HashSize]; - - /* Insert RepeaterInfo into the SHA-1 transform */ - Buf[0] = (u8) (RepeaterInfo & 0xFFu); - Buf[1] = (u8) ((RepeaterInfo >> 8) & 0xFFu); - SHA1Input(&Sha1Context, Buf, 2); - - /* Insert the Mo into the SHA-1 transform */ - Mo = XHdcp1x_CipherGetMo(CipherPtr); - XHDCP1X_PORT_UINT_TO_BUF(Buf, Mo, 64); - SHA1Input(&Sha1Context, Buf, 8); - - /* Finalize the SHA-1 result and confirm success */ - if (SHA1Result(&Sha1Context, Sha1Result) == shaSuccess) { - u8 Offset = XHDCP1X_PORT_OFFSET_VH0; - const u8* Sha1Buf = Sha1Result; - int NumIterations = (SHA1HashSize >> 2); - - /* Iterate through the SHA-1 chunks */ - do { - u32 CalcValue = 0; - u32 ReadValue = 0; - - /* Determine CalcValue */ - CalcValue = *Sha1Buf++; - CalcValue <<= 8; - CalcValue |= *Sha1Buf++; - CalcValue <<= 8; - CalcValue |= *Sha1Buf++; - CalcValue <<= 8; - CalcValue |= *Sha1Buf++; - - /* Read the value from the far end */ - if (XHdcp1x_PortRead(PortPtr, Offset, Buf, - 4) > 0) { - /* Determine ReadValue */ - XHDCP1X_PORT_BUF_TO_UINT(ReadValue, - Buf, 32); - } - else { - /* Update ReadValue */ - ReadValue = 0; - - /* Update the statistics */ - InstancePtr->Stats.ReadFailures++; - } - - /* Check for mismatch */ - if (CalcValue != ReadValue) { - IsValid = FALSE; - } - - /* Update for loop */ - Offset += 4; - NumIterations--; - } - while (NumIterations > 0); - } - /* Otherwise */ - else { - IsValid = FALSE; - } - } - - /* Return */ - return (IsValid); -} - -/*****************************************************************************/ -/** -* -* This function reads the ksv list from an attached repeater -* -* @param InstancePtr the hdcp state machine -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void ReadKsvList(XHdcp1x_Tx* InstancePtr, tState* NextStatePtr) -{ - int NumAttempts = 3; - int KsvListIsValid = FALSE; - u16 RepeaterInfo = 0; - - /* Determine RepeaterInfo */ - RepeaterInfo = (u16) (InstancePtr->StateHelper & 0x0FFFu); - - /* Iterate through the attempts */ - do { - /* Attempt to validate the ksv list */ - KsvListIsValid = ValidateKsvList(InstancePtr, RepeaterInfo); - - /* Update for loop */ - NumAttempts--; - } - while ((NumAttempts > 0) && (!KsvListIsValid)); - - /* Check for success */ - if (KsvListIsValid) { - /* Log */ - DebugLog(InstancePtr, "ksv list validated"); - - /* Update NextStatePtr */ - *NextStatePtr = STATE_AUTHENTICATED; - } - else { - /* Log */ - DebugLog(InstancePtr, "ksv list invalid"); - - /* Update NextStatePtr */ - *NextStatePtr = STATE_UNAUTHENTICATED; - } - - return; -} - -/*****************************************************************************/ -/** - * - * This function queries a a handler to check if its been authenticated - * - * @param InstancePtr the hdcp state machine - * - * @return - * Truth value indicating authenticated (true) or not (false) - * - * @note - * None. - * - ******************************************************************************/ -static int IsAuthenticated(const XHdcp1x_Tx* InstancePtr) -{ - /* Locals */ - int Authenticated = FALSE; - - /* Which state? */ - switch (InstancePtr->CurrentState) { - - /* For the authenticated and link integrity check states */ - case STATE_AUTHENTICATED: - case STATE_LINKINTEGRITYCHECK: - Authenticated = TRUE; - break; - /* Otherwise */ - default: - Authenticated = FALSE; - break; - } - - return (Authenticated); -} - -/*****************************************************************************/ -/** -* -* This function runs the "disabled" state of the transmit state machine -* -* @param InstancePtr the transmitter instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunDisabledState(XHdcp1x_Tx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For enable */ - case EVENT_ENABLE: - *NextStatePtr = STATE_UNAUTHENTICATED; - if ((InstancePtr->Flags &FLAG_PHY_UP) == 0) { - *NextStatePtr = STATE_PHYDOWN; - } - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - InstancePtr->Flags &= ~FLAG_PHY_UP; - break; - /* For physical layer up */ - case EVENT_PHYUP: - InstancePtr->Flags |= FLAG_PHY_UP; - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "determine rx capable" state of the transmit state -* machine -* -* @param InstancePtr the transmitter instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunDetermineRxCapableState(XHdcp1x_Tx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "exchange ksvs" state of the transmit state machine -* -* @param InstancePtr the transmitter instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunExchangeKsvsState(XHdcp1x_Tx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "computations" state of the transmit state machine -* -* @param InstancePtr the transmitter instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunComputationsState(XHdcp1x_Tx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For authenticate */ - case EVENT_AUTHENTICATE: - *NextStatePtr = STATE_DETERMINERXCAPABLE; - break; - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* For poll */ - case EVENT_POLL: - PollForComputations(InstancePtr, NextStatePtr); - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "validate-rx" state of the transmit state machine -* -* @param InstancePtr the transmitter instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunValidateRxState(XHdcp1x_Tx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For authenticate */ - case EVENT_AUTHENTICATE: - *NextStatePtr = STATE_DETERMINERXCAPABLE; - break; - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* For timeout */ - case EVENT_TIMEOUT: - DebugLog(InstancePtr, "validate-rx timeout"); - ValidateRx(InstancePtr, NextStatePtr); - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "authenticated" state of the transmit state machine -* -* @param InstancePtr the transmitter instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunAuthenticatedState(XHdcp1x_Tx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For authenticate */ - case EVENT_AUTHENTICATE: - *NextStatePtr = STATE_DETERMINERXCAPABLE; - break; - /* For check */ - case EVENT_CHECK: - *NextStatePtr = STATE_LINKINTEGRITYCHECK; - break; - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "link-integrity check" state of the transmit state -* machine -* -* @param InstancePtr the transmitter instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunLinkIntegrityCheckState(XHdcp1x_Tx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For authenticate */ - case EVENT_AUTHENTICATE: - *NextStatePtr = STATE_DETERMINERXCAPABLE; - break; - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* For poll */ - case EVENT_POLL: - CheckLinkIntegrity(InstancePtr, NextStatePtr); - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "test-for-repeater" state of the transmit state -* machine -* -* @param InstancePtr the transmitter instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunTestForRepeaterState(XHdcp1x_Tx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For authenticate */ - case EVENT_AUTHENTICATE: - *NextStatePtr = STATE_DETERMINERXCAPABLE; - break; - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* For poll */ - case EVENT_POLL: - TestForRepeater(InstancePtr, NextStatePtr); - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "wait-for-ready" state of the transmit state machine -* -* @param InstancePtr the transmitter instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunWaitForReadyState(XHdcp1x_Tx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For authenticate */ - case EVENT_AUTHENTICATE: - *NextStatePtr = STATE_DETERMINERXCAPABLE; - break; - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* For poll */ - case EVENT_POLL: - PollForWaitForReady(InstancePtr, NextStatePtr); - break; - /* For timeout */ - case EVENT_TIMEOUT: - DebugLog(InstancePtr, "wait-for-ready timeout"); - PollForWaitForReady(InstancePtr, NextStatePtr); - if (*NextStatePtr == STATE_WAITFORREADY) - *NextStatePtr = STATE_UNAUTHENTICATED; - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "read-ksv-list" state of the transmit state machine -* -* @param InstancePtr the transmitter instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunReadKsvListState(XHdcp1x_Tx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For authenticate */ - case EVENT_AUTHENTICATE: - *NextStatePtr = STATE_DETERMINERXCAPABLE; - break; - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function runs the "unauthenticated" state of the transmit state machine -* -* @param InstancePtr the transmitter instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunUnauthenticatedState(XHdcp1x_Tx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For authenticate */ - case EVENT_AUTHENTICATE: - *NextStatePtr = STATE_DETERMINERXCAPABLE; - break; - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer down */ - case EVENT_PHYDOWN: - *NextStatePtr = STATE_PHYDOWN; - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - - -/*****************************************************************************/ -/** -* -* This function runs the "physical-layer-down" state of the transmit state -* machine -* -* @param InstancePtr the transmitter instance -* @param Event the event to process -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void RunPhysicalLayerDownState(XHdcp1x_Tx *InstancePtr, tEvent Event, - tState *NextStatePtr) -{ - /* Which event? */ - switch (Event) { - - /* For disable */ - case EVENT_DISABLE: - *NextStatePtr = STATE_DISABLED; - break; - /* For physical layer up */ - case EVENT_PHYUP: - *NextStatePtr = STATE_UNAUTHENTICATED; - if (InstancePtr->EncryptionMap != 0) { - PostEvent(InstancePtr, EVENT_AUTHENTICATE); - } - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function enters a state -* -* @param InstancePtr the hdcp state machine -* @param State the state to enter -* @param NextStatePtr the next state -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void EnterState(XHdcp1x_Tx *InstancePtr, tState State, - tState *NextStatePtr) -{ - /* Which state? */ - switch (State) { - - /* For the disabled state */ - case STATE_DISABLED: - Disable(InstancePtr); - break; - /* For determine rx capable */ - case STATE_DETERMINERXCAPABLE: - InstancePtr->Flags |= FLAG_PHY_UP; - SetCheckLinkState(InstancePtr, FALSE); - DisableEncryption(InstancePtr); - CheckRxCapable(InstancePtr, NextStatePtr); - break; - /* For the exchange ksvs state */ - case STATE_EXCHANGEKSVS: - InstancePtr->StateHelper = 0; - ExchangeKsvs(InstancePtr, NextStatePtr); - break; - /* For the computations state */ - case STATE_COMPUTATIONS: - StartComputations(InstancePtr, NextStatePtr); - break; - /* For the validate rx state */ - case STATE_VALIDATERX: - InstancePtr->StateHelper = 0; - StartTimer(InstancePtr, TMO_100MS); - break; - /* For the wait for ready state */ - case STATE_WAITFORREADY: - InstancePtr->StateHelper = 0; - StartTimer(InstancePtr, (5*TMO_1SECOND)); - break; - /* For the read ksv list state */ - case STATE_READKSVLIST: - ReadKsvList(InstancePtr, NextStatePtr); - break; - /* For the authenticated state */ - case STATE_AUTHENTICATED: - InstancePtr->StateHelper = 0; - EnableEncryption(InstancePtr); - if (InstancePtr->PreviousState != STATE_LINKINTEGRITYCHECK) { - InstancePtr->Stats.AuthPassed++; - SetCheckLinkState(InstancePtr, TRUE); - DebugLog(InstancePtr, "authenticated"); - } - break; - /* For the link integrity check state */ - case STATE_LINKINTEGRITYCHECK: - CheckLinkIntegrity(InstancePtr, NextStatePtr); - break; - /* For the unauthenticated state */ - case STATE_UNAUTHENTICATED: - InstancePtr->Flags &= ~FLAG_IS_REPEATER; - InstancePtr->Flags |= FLAG_PHY_UP; - DisableEncryption(InstancePtr); - break; - /* For physical layer down */ - case STATE_PHYDOWN: - InstancePtr->Flags &= ~FLAG_PHY_UP; - DisableEncryption(InstancePtr); - XHdcp1x_CipherDisable(&InstancePtr->Cipher); - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function exits a state -* -* @param InstancePtr the hdcp state machine -* @param State the state to exit -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void ExitState(XHdcp1x_Tx *InstancePtr, tState State) -{ - /* Which state? */ - switch (State) { - - /* For the disabled state */ - case STATE_DISABLED: - Enable(InstancePtr); - break; - /* For the computations state */ - case STATE_COMPUTATIONS: - InstancePtr->StateHelper = 0; - break; - /* For the validate rx state */ - case STATE_VALIDATERX: - StopTimer(InstancePtr); - break; - /* For the wait for ready state */ - case STATE_WAITFORREADY: - StopTimer(InstancePtr); - break; - /* For the read ksv list state */ - case STATE_READKSVLIST: - InstancePtr->StateHelper = 0; - break; - /* For physical layer down */ - case STATE_PHYDOWN: - XHdcp1x_CipherEnable(&InstancePtr->Cipher); - break; - /* Otherwise */ - default: - /* Do nothing */ - break; - } - - /* Return */ - return; -} - -/*****************************************************************************/ -/** -* -* This function drives a transmit state machine -* -* @param InstancePtr the hdcp state machine -* @param theEvent the event to process -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void DoTheState(XHdcp1x_Tx *InstancePtr, tEvent Event) -{ - tState NextState = InstancePtr->CurrentState; - - /* Which state? */ - switch (InstancePtr->CurrentState) { - - /* For the disabled state */ - case STATE_DISABLED: - RunDisabledState(InstancePtr, Event, &NextState); - break; - /* For determine rx capable state */ - case STATE_DETERMINERXCAPABLE: - RunDetermineRxCapableState(InstancePtr, Event, &NextState); - break; - /* For exchange ksvs state */ - case STATE_EXCHANGEKSVS: - RunExchangeKsvsState(InstancePtr, Event, &NextState); - break; - /* For the computations state */ - case STATE_COMPUTATIONS: - RunComputationsState(InstancePtr, Event, &NextState); - break; - /* For the validate rx state */ - case STATE_VALIDATERX: - RunValidateRxState(InstancePtr, Event, &NextState); - break; - /* For the authenticated state */ - case STATE_AUTHENTICATED: - RunAuthenticatedState(InstancePtr, Event, &NextState); - break; - /* For the link integrity check state */ - case STATE_LINKINTEGRITYCHECK: - RunLinkIntegrityCheckState(InstancePtr, Event, &NextState); - break; - /* For the test for repeater state */ - case STATE_TESTFORREPEATER: - RunTestForRepeaterState(InstancePtr, Event, &NextState); - break; - /* For the wait for ready state */ - case STATE_WAITFORREADY: - RunWaitForReadyState(InstancePtr, Event, &NextState); - break; - /* For the reads ksv list state */ - case STATE_READKSVLIST: - RunReadKsvListState(InstancePtr, Event, &NextState); - break; - /* For the unauthenticated state */ - case STATE_UNAUTHENTICATED: - RunUnauthenticatedState(InstancePtr, Event, &NextState); - break; - /* For the physical layer down state */ - case STATE_PHYDOWN: - RunPhysicalLayerDownState(InstancePtr, Event, &NextState); - break; - /* Otherwise */ - default: - break; - } - - /* Check for state change */ - while (InstancePtr->CurrentState != NextState) { - - /* Perform the state transition */ - ExitState(InstancePtr, InstancePtr->CurrentState); - InstancePtr->PreviousState = InstancePtr->CurrentState; - InstancePtr->CurrentState = NextState; - EnterState(InstancePtr, InstancePtr->CurrentState, &NextState); - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function initializes a transmit state machine -* -* @param InstancePtr the receiver instance -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void Init(XHdcp1x_Tx *InstancePtr) -{ - tState DummyState = STATE_DISABLED; - - /* Update theHandler */ - InstancePtr->PendingEvents = 0; - - /* Kick the state machine */ - EnterState(InstancePtr, STATE_DISABLED, &DummyState); - - return; -} - -/*****************************************************************************/ -/** -* -* This function processes the events pending on a state machine -* -* @param InstancePtr the receiver instance -* -* @return -* void -* -* @note -* None. -* -******************************************************************************/ -static void ProcessPending(XHdcp1x_Tx *InstancePtr) -{ - /* Check for any pending events */ - if (InstancePtr->PendingEvents != 0) { - u16 Pending = InstancePtr->PendingEvents; - tEvent Event = EVENT_NULL; - - /* Update InstancePtr */ - InstancePtr->PendingEvents = 0; - - /* Iterate through thePending */ - do { - /* Check for a pending event */ - if ((Pending & 1u) != 0) { - DoTheState(InstancePtr, Event); - } - - /* Update for loop */ - Pending >>= 1; - Event++; - } - while (Pending != 0); - } - - return; -} - -/*****************************************************************************/ -/** -* -* This function initializes an hdcp interface -* -* @param InstancePtr the transmitter instance -* @param CfgPtr the configuration of the instance -* @param PhyIfPtr pointer to the underlying physical interface -* -* @return -* XST_SUCCESS if successful. -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_TxCfgInitialize(XHdcp1x_Tx *InstancePtr, - const XHdcp1x_Config *CfgPtr, void* PhyIfPtr) + const XHdcp1x_Config *CfgPtr, void *PhyIfPtr) { XHdcp1x_Cipher *CipherPtr = NULL; XHdcp1x_Port *PortPtr = NULL; @@ -2202,18 +241,16 @@ int XHdcp1x_TxCfgInitialize(XHdcp1x_Tx *InstancePtr, /*****************************************************************************/ /** +* This function polls an HDCP interface. * -* This function polls an hdcp interface -* -* @param InstancePtr the transmitter instance +* @param InstancePtr is the transmitter instance. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * - ******************************************************************************/ +******************************************************************************/ int XHdcp1x_TxPoll(XHdcp1x_Tx *InstancePtr) { int Status = XST_SUCCESS; @@ -2232,18 +269,16 @@ int XHdcp1x_TxPoll(XHdcp1x_Tx *InstancePtr) /*****************************************************************************/ /** +* This function resets an HDCP interface. * -* This function resets an hdcp interface -* -* @param InstancePtr the transmitter instance +* @param InstancePtr is the transmitter instance. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* This function disables and then re-enables the interface. +* @note This function disables and then re-enables the interface. * - ******************************************************************************/ +******************************************************************************/ int XHdcp1x_TxReset(XHdcp1x_Tx *InstancePtr) { int Status = XST_SUCCESS; @@ -2260,18 +295,16 @@ int XHdcp1x_TxReset(XHdcp1x_Tx *InstancePtr) /*****************************************************************************/ /** +* This function enables an HDCP interface. * -* This function enables an hdcp interface -* -* @param InstancePtr the transmitter instance +* @param InstancePtr is the transmitter instance. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * - ******************************************************************************/ +******************************************************************************/ int XHdcp1x_TxEnable(XHdcp1x_Tx *InstancePtr) { int Status = XST_SUCCESS; @@ -2287,18 +320,16 @@ int XHdcp1x_TxEnable(XHdcp1x_Tx *InstancePtr) /*****************************************************************************/ /** +* This function disables an HDCP interface. * -* This function disables an hdcp interface -* -* @param InstancePtr the transmitter instance +* @param InstancePtr is the transmitter instance. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * - ******************************************************************************/ +******************************************************************************/ int XHdcp1x_TxDisable(XHdcp1x_Tx *InstancePtr) { int Status = XST_SUCCESS; @@ -2314,19 +345,17 @@ int XHdcp1x_TxDisable(XHdcp1x_Tx *InstancePtr) /*****************************************************************************/ /** +* This function updates the physical state of an HDCP interface. * -* This function updates the physical state of an hdcp interface -* -* @param InstancePtr the transmitter instance -* @param IsUp truth value indicating the status of physical interface +* @param InstancePtr is the transmitter instance. +* @param IsUp is truth value indicating the status of physical interface. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * - ******************************************************************************/ +******************************************************************************/ int XHdcp1x_TxSetPhysicalState(XHdcp1x_Tx *InstancePtr, int IsUp) { int Status = XST_SUCCESS; @@ -2348,19 +377,17 @@ int XHdcp1x_TxSetPhysicalState(XHdcp1x_Tx *InstancePtr, int IsUp) /*****************************************************************************/ /** +* This function set the lane count of an HDCP interface. * -* This function set the lane count of an hdcp interface -* -* @param InstancePtr the transmitter instance -* @param LaneCount the number of lanes of the interface +* @param InstancePtr is the transmitter instance. +* @param LaneCount is the number of lanes of the interface. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * - ******************************************************************************/ +******************************************************************************/ int XHdcp1x_TxSetLaneCount(XHdcp1x_Tx *InstancePtr, int LaneCount) { /* Verify arguments. */ @@ -2373,16 +400,14 @@ int XHdcp1x_TxSetLaneCount(XHdcp1x_Tx *InstancePtr, int LaneCount) /*****************************************************************************/ /** +* This function initiates authentication on an interface. * -* This function initiates authentication on an interface -* -* @param InstancePtr the transmitter instance +* @param InstancePtr is the transmitter instance. * * @return -* XST_SUCCESS if successful. +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_TxAuthenticate(XHdcp1x_Tx *InstancePtr) @@ -2400,17 +425,14 @@ int XHdcp1x_TxAuthenticate(XHdcp1x_Tx *InstancePtr) /*****************************************************************************/ /** -* * This function queries an interface to check if authentication is still in -* progress +* progress. * -* @param InstancePtr the transmitter instance +* @param InstancePtr is the transmitter instance. * -* @return -* Truth value indicating in progress (true) or not (false) +* @return Truth value indicating in progress (true) or not (false). * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_TxIsInProgress(const XHdcp1x_Tx *InstancePtr) @@ -2422,18 +444,18 @@ int XHdcp1x_TxIsInProgress(const XHdcp1x_Tx *InstancePtr) /* Which state? */ switch (InstancePtr->CurrentState) { + /* For the "steady" states */ + case STATE_DISABLED: + case STATE_UNAUTHENTICATED: + case STATE_AUTHENTICATED: + case STATE_LINKINTEGRITYCHECK: + IsInProgress = FALSE; + break; - /* For the "steady" states */ - case STATE_DISABLED: - case STATE_UNAUTHENTICATED: - case STATE_AUTHENTICATED: - case STATE_LINKINTEGRITYCHECK: - IsInProgress = FALSE; - break; - /* Otherwise */ - default: - IsInProgress = TRUE; - break; + /* Otherwise */ + default: + IsInProgress = TRUE; + break; } return (IsInProgress); @@ -2441,16 +463,13 @@ int XHdcp1x_TxIsInProgress(const XHdcp1x_Tx *InstancePtr) /*****************************************************************************/ /** +* This function queries an interface to check if its been authenticated. * -* This function queries an interface to check if its been authenticated +* @param InstancePtr is the transmitter instance. * -* @param InstancePtr the transmitter instance +* @return Truth value indicating authenticated (true) or not (false). * -* @return -* Truth value indicating authenticated (true) or not (false) -* -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_TxIsAuthenticated(const XHdcp1x_Tx *InstancePtr) @@ -2463,16 +482,13 @@ int XHdcp1x_TxIsAuthenticated(const XHdcp1x_Tx *InstancePtr) /*****************************************************************************/ /** +* This function retrieves the current encryption stream map. * -* This function retrieves the current encryption stream map +* @param InstancePtr the transmitter instance. * -* @param InstancePtr the transmitter instance +* @return The current encryption stream map. * -* @return -* The current encryption stream map -* -* @note -* None. +* @note None. * ******************************************************************************/ u64 XHdcp1x_TxGetEncryption(const XHdcp1x_Tx *InstancePtr) @@ -2485,22 +501,19 @@ u64 XHdcp1x_TxGetEncryption(const XHdcp1x_Tx *InstancePtr) /*****************************************************************************/ /** +* This function enables encryption on set of streams on an HDCP interface. * -* This function enables encryption on set of streams on a hdcp interface -* -* @param InstancePtr the transmitter instance -* @param StreamMap the bit map of streams to enable encryption on +* @param InstancePtr is the transmitter instance. +* @param StreamMap is the bit map of streams to enable encryption on. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_TxEnableEncryption(XHdcp1x_Tx *InstancePtr, u64 StreamMap) { - /* Locals */ int Status = XST_SUCCESS; /* Verify arguments. */ @@ -2519,22 +532,19 @@ int XHdcp1x_TxEnableEncryption(XHdcp1x_Tx *InstancePtr, u64 StreamMap) /*****************************************************************************/ /** +* This function disables encryption on set of streams on an HDCP interface. * -* This function disables encryption on set of streams on a hdcp interface -* -* @param InstancePtr the transmitter instance -* @param StreamMap the bit map of streams to disable encryption on +* @param InstancePtr is the transmitter instance. +* @param StreamMap is the bit map of streams to disable encryption on. * * @return -* XST_SUCCESS if successful +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ int XHdcp1x_TxDisableEncryption(XHdcp1x_Tx *InstancePtr, u64 StreamMap) { - /* Locals */ int Status = XST_SUCCESS; /* Verify arguments. */ @@ -2554,16 +564,13 @@ int XHdcp1x_TxDisableEncryption(XHdcp1x_Tx *InstancePtr, u64 StreamMap) /*****************************************************************************/ /** +* This function handles a timeout on an HDCP interface. * -* This function handles a timeout on an hdcp interface +* @param InstancePtr is the transmitter instance. * -* @param InstancePtr the transmitter instance +* @return None. * -* @return -* void -* -* @note -* None. +* @note None. * ******************************************************************************/ void XHdcp1x_TxHandleTimeout(XHdcp1x_Tx *InstancePtr) @@ -2573,89 +580,21 @@ void XHdcp1x_TxHandleTimeout(XHdcp1x_Tx *InstancePtr) /* Post the timeout */ PostEvent(InstancePtr, EVENT_TIMEOUT); - return; } /*****************************************************************************/ /** +* This function implements the debug display output for transmit instances. * -* This function converts from a state to a display string -* -* @param State the state to convert +* @param InstancePtr is the receiver instance. * * @return -* The corresponding display string +* - XST_SUCCESS if successful. * -* @note -* None. +* @note None. * ******************************************************************************/ -static const char* StateToString(tState State) -{ - const char* String = NULL; - - /* Which state? */ - switch (State) { - - case STATE_DISABLED: - String = "disabled"; - break; - case STATE_DETERMINERXCAPABLE: - String = "determine-rx-capable"; - break; - case STATE_EXCHANGEKSVS: - String = "exchange-ksvs"; - break; - case STATE_COMPUTATIONS: - String = "computations"; - break; - case STATE_VALIDATERX: - String = "validate-rx"; - break; - case STATE_AUTHENTICATED: - String = "authenticated"; - break; - case STATE_LINKINTEGRITYCHECK: - String = "link-integrity-check"; - break; - case STATE_TESTFORREPEATER: - String = "test-for-repeater"; - break; - case STATE_WAITFORREADY: - String = "wait-for-ready"; - break; - case STATE_READKSVLIST: - String = "read-ksv-list"; - break; - case STATE_UNAUTHENTICATED: - String = "unauthenticated"; - break; - case STATE_PHYDOWN: - String = "physical-layer-down"; - break; - default: - String = "???"; - break; - } - - return (String); -} - -/*****************************************************************************/ -/** -* -* This function implements the debug display output for transmit instances -* -* @param InstancePtr the receiver instance -* -* @return -* XST_SUCCESS if successful. -* -* @note -* None. -* -******************************************************************************/ -int XHdcp1x_TxInfo(const XHdcp1x_Tx* InstancePtr) +int XHdcp1x_TxInfo(const XHdcp1x_Tx *InstancePtr) { u32 Version = 0; @@ -2715,3 +654,1918 @@ int XHdcp1x_TxInfo(const XHdcp1x_Tx* InstancePtr) return (XST_SUCCESS); } + +/*****************************************************************************/ +/** +* This function logs a debug message on behalf of a handler state machine. +* +* @param InstancePtr is the receiver instance. +* @param LogMsg is the message to log. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void DebugLog(const XHdcp1x_Tx *InstancePtr, const char *LogMsg) +{ + char Label[16]; + + /* Format Label */ + snprintf(Label, 16, "hdcp-tx(%d) - ", InstancePtr->CfgPtr->DeviceId); + + /* Log it */ + XHDCP1X_DEBUG_LOGMSG(Label); + XHDCP1X_DEBUG_LOGMSG(LogMsg); + XHDCP1X_DEBUG_LOGMSG("\r\n"); +} + +/*****************************************************************************/ +/** +* This function posts an event to a state machine. +* +* @param InstancePtr is the transmitter instance. +* @param Event is the event to post. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void PostEvent(XHdcp1x_Tx *InstancePtr, tEvent Event) +{ + /* Check for disable and clear any pending enable */ + if (Event == EVENT_DISABLE) { + InstancePtr->PendingEvents &= ~(1u << EVENT_ENABLE); + } + /* Check for phy-down and clear any pending phy-up */ + else if (Event == EVENT_PHYDOWN) { + InstancePtr->PendingEvents &= ~(1u << EVENT_PHYUP); + } + + /* Post it */ + InstancePtr->PendingEvents |= (1u << Event); +} + +/*****************************************************************************/ +/** +* This function starts a state machine's timer. +* +* @param InstancePtr is the state machine. +* @param TimeoutInMs is the timeout in milli-seconds. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void StartTimer(XHdcp1x_Tx *InstancePtr, u16 TimeoutInMs) +{ + /* Start it */ + XHdcp1x_PlatformTimerStart((XHdcp1x *)InstancePtr, TimeoutInMs); +} + +/*****************************************************************************/ +/** +* This function stops a state machine's timer. +* +* @param InstancePtr is the state machine. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void StopTimer(XHdcp1x_Tx *InstancePtr) +{ + /* Stop it */ + XHdcp1x_PlatformTimerStop((XHdcp1x *)InstancePtr); +} + +/*****************************************************************************/ +/** +* +* This function busy delays a state machine. +* +* @param InstancePtr is the state machine. +* @param TimeoutInMs is the delay time in milli-seconds. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void BusyDelay(XHdcp1x_Tx *InstancePtr, u16 DelayInMs) +{ + /* Busy wait */ + XHdcp1x_PlatformTimerBusy((XHdcp1x *)InstancePtr, DelayInMs); +} + +/*****************************************************************************/ +/** +* This function acts as the reauthentication callback for a state machine. +* +* @param Parameter is the parameter specified during registration. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void ReauthenticateCallback(void *Parameter) +{ + XHdcp1x_Tx *InstancePtr = Parameter; + + /* Update statistics */ + InstancePtr->Stats.ReauthRequested++; + + /* Post the re-authentication request */ + PostEvent(InstancePtr, EVENT_AUTHENTICATE); +} + +/*****************************************************************************/ +/** +* This function acts as the check link callback for a state machine. +* +* @param Parameter is the parameter specified during registration. +* +* @return Mpme/ +* +* @note None. +* +******************************************************************************/ +static void CheckLinkCallback(void *Parameter) +{ + XHdcp1x_Tx *InstancePtr = Parameter; + + /* Post the check request */ + PostEvent(InstancePtr, EVENT_CHECK); +} + +/*****************************************************************************/ +/** +* This function sets the check link state of the handler. +* +* @param InstancePtr is the HDCP state machine. +* @param IsEnabled is truth value indicating on/off. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void SetCheckLinkState(XHdcp1x_Tx *InstancePtr, int IsEnabled) +{ + /* Check for HDMI */ + if (IsHDMI(InstancePtr)) { + XHdcp1x_Cipher *CipherPtr = &(InstancePtr->Cipher); + + /* Check for enabled */ + if (IsEnabled) { + /* Register Callback */ + XHdcp1x_CipherSetCallback(CipherPtr, + XHDCP1X_CIPHER_HANDLER_Ri_UPDATE, + &CheckLinkCallback, InstancePtr); + + /* Enable it */ + XHdcp1x_CipherSetRiUpdate(CipherPtr, TRUE); + } + /* Otherwise */ + else { + /* Disable it */ + XHdcp1x_CipherSetRiUpdate(CipherPtr, FALSE); + } + } +} + +/*****************************************************************************/ +/** +* This function enables encryption for a state machine. +* +* @param InstancePtr is the HDCP state machine. +* +* @return None. +* +* @note This function inserts a 5ms delay for things to settle when +* encryption is actually being disabled. +* +******************************************************************************/ +static void EnableEncryption(XHdcp1x_Tx *InstancePtr) +{ + /* Check for encryption enabled */ + if (InstancePtr->EncryptionMap != 0) { + u64 StreamMap = 0; + + /* Determine StreamMap */ + StreamMap = XHdcp1x_CipherGetEncryption(&InstancePtr->Cipher); + + /* Check if there is something to do */ + if (StreamMap != InstancePtr->EncryptionMap) { + /* Wait a bit */ + BusyDelay(InstancePtr, TMO_5MS); + + /* Enable it */ + XHdcp1x_CipherEnableEncryption(&InstancePtr->Cipher, + InstancePtr->EncryptionMap); + } + } +} + +/*****************************************************************************/ +/** +* This function disables encryption for a state machine. +* +* @param InstancePtr is the HDCP state machine. +* +* @return None. +* +* @note This function inserts a 5ms delay for things to settle when +* encryption is actually being disabled. +* +******************************************************************************/ +static void DisableEncryption(XHdcp1x_Tx *InstancePtr) +{ + u64 StreamMap = XHdcp1x_CipherGetEncryption(&InstancePtr->Cipher); + + /* Check if encryption actually enabled */ + if (StreamMap != 0) { + /* Update StreamMap for all stream */ + StreamMap = (u64)(-1); + + /* Disable it all */ + XHdcp1x_CipherDisableEncryption(&InstancePtr->Cipher, + StreamMap); + + /* Wait at least a frame */ + BusyDelay(InstancePtr, TMO_5MS); + } +} + +/*****************************************************************************/ +/** +* This function enables a state machine. +* +* @param InstancePtr is the HDCP state machine. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void Enable(XHdcp1x_Tx *InstancePtr) +{ + /* Clear statistics */ + memset(&(InstancePtr->Stats), 0, sizeof(InstancePtr->Stats)); + + /* Enable the crypto engine */ + XHdcp1x_CipherEnable(&InstancePtr->Cipher); + + /* Register the re-authentication callback */ + XHdcp1x_PortSetCallback(&InstancePtr->Port, + XHDCP1X_PORT_HANDLER_AUTHENTICATE, + &ReauthenticateCallback, InstancePtr); + + /* Enable the hdcp port */ + XHdcp1x_PortEnable(&InstancePtr->Port); +} + +/*****************************************************************************/ +/** +* This function disables a state machine. +* +* @param InstancePtr is the HDCP state machine. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void Disable(XHdcp1x_Tx *InstancePtr) +{ + /* Disable the hdcp port */ + XHdcp1x_PortDisable(&InstancePtr->Port); + + /* Disable the cryto engine */ + XHdcp1x_CipherDisable(&InstancePtr->Cipher); + + /* Disable the timer */ + StopTimer(InstancePtr); + + /* Update InstancePtr */ + InstancePtr->Flags &= ~FLAG_IS_REPEATER; + InstancePtr->StateHelper = 0; + InstancePtr->EncryptionMap = 0; +} + +/*****************************************************************************/ +/** +* This function checks to ensure that the remote end is HDCP capable. +* +* @param InstancePtr is the HDCP state machine. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void CheckRxCapable(const XHdcp1x_Tx *InstancePtr, tState *NextStatePtr) +{ + /* Check for capable */ + if (XHdcp1x_PortIsCapable(&InstancePtr->Port)) { + /* Log */ + DebugLog(InstancePtr, "rx hdcp capable"); + + /* Update NextStatePtr */ + *NextStatePtr = STATE_EXCHANGEKSVS; + } + else { + /* Log */ + DebugLog(InstancePtr, "rx not capable"); + + /* Update NextStatePtr */ + *NextStatePtr = STATE_UNAUTHENTICATED; + } +} + +/*****************************************************************************/ +/** +* This function generates the An from a random number generator. +* +* @param InstancePtr is the HDCP state machine. +* +* @return A 64-bit pseudo random number (An). +* +* @note None. +* +******************************************************************************/ +static u64 GenerateAn(XHdcp1x_Tx *InstancePtr) +{ + XHdcp1x_Cipher *CipherPtr = &InstancePtr->Cipher; + u64 An = 0; + + /* Attempt to generate An */ + if (XHdcp1x_CipherDoRequest(CipherPtr, XHDCP1X_CIPHER_REQUEST_RNG) == + XST_SUCCESS) { + /* Wait until done */ + while (!XHdcp1x_CipherIsRequestComplete(CipherPtr)); + + /* Update theAn */ + An = XHdcp1x_CipherGetMi(CipherPtr); + } + + /* Check if zero */ + if (An == 0) { + An = 0x351F7175406A74Dull; + } + + return (An); +} + +/*****************************************************************************/ +/** +* This function validates a KSV value as having 20 1s and 20 0s. +* +* @param Ksv is the value to validate. +* +* @return Truth value indicating valid (TRUE) or not (FALSE). +* +* @note None. +* +******************************************************************************/ +static int IsKsvValid(u64 Ksv) +{ + int IsValid = FALSE; + int NumOnes = 0; + + /* Determine NumOnes */ + while (Ksv != 0) { + if ((Ksv & 1) != 0) { + NumOnes++; + } + Ksv >>= 1; + } + + /* Check for 20 1s */ + if (NumOnes == 20) { + IsValid = TRUE; + } + + return (IsValid); +} + +/*****************************************************************************/ +/** +* This function exchanges the ksvs between the two ends of the link. +* +* @param InstancePtr is the HDCP state machine. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void ExchangeKsvs(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr) +{ + XHdcp1x_Port *PortPtr = &InstancePtr->Port; + XHdcp1x_Cipher *CipherPtr = &InstancePtr->Cipher; + u8 Buf[8]; + + /* Initialize Buf */ + memset(Buf, 0, 8); + + /* Update NextStatePtr - assume failure */ + *NextStatePtr = STATE_UNAUTHENTICATED; + + /* Read the Bksv from remote end */ + if (XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_BKSV, Buf, 5) > 0) { + u64 RemoteKsv = 0; + + /* Determine theRemoteKsv */ + XHDCP1X_PORT_BUF_TO_UINT(RemoteKsv, Buf, + XHDCP1X_PORT_SIZE_BKSV * 8); + + /* Check for invalid */ + if (!IsKsvValid(RemoteKsv)) { + DebugLog(InstancePtr, "Bksv invalid"); + } + /* Check for revoked */ + else if (XHdcp1x_PlatformIsKsvRevoked((XHdcp1x *)InstancePtr, + RemoteKsv)) { + DebugLog(InstancePtr, "Bksv is revoked"); + } + /* Otherwise we're good to go */ + else { + u64 LocalKsv = 0; + u64 An = 0; + + /* Check for repeater and update InstancePtr */ + if (XHdcp1x_PortIsRepeater(&InstancePtr->Port)) { + InstancePtr->Flags |= FLAG_IS_REPEATER; + } + else { + InstancePtr->Flags &= ~FLAG_IS_REPEATER; + } + + /* Generate theAn */ + An = GenerateAn(InstancePtr); + + /* Save theAn into the state helper for use later */ + InstancePtr->StateHelper = An; + + /* Determine theLocalKsv */ + LocalKsv = XHdcp1x_CipherGetLocalKsv(CipherPtr); + + /* Load the cipher with the remote ksv */ + XHdcp1x_CipherSetRemoteKsv(CipherPtr, RemoteKsv); + + /* Send An to remote */ + XHDCP1X_PORT_UINT_TO_BUF(Buf, An, + XHDCP1X_PORT_SIZE_AN * 8); + XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_AN, Buf, + XHDCP1X_PORT_SIZE_AN); + + /* Send AKsv to remote */ + XHDCP1X_PORT_UINT_TO_BUF(Buf, LocalKsv, + XHDCP1X_PORT_SIZE_AKSV * 8); + XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_AKSV, + Buf, XHDCP1X_PORT_SIZE_AKSV); + + /* Update NextStatePtr */ + *NextStatePtr = STATE_COMPUTATIONS; + } + } + /* Otherwise */ + else { + /* Update the statistics */ + InstancePtr->Stats.ReadFailures++; + } +} + +/*****************************************************************************/ +/** +* This function initiates the computations for a state machine. +* +* @param InstancePtr is the HDCP receiver state machine. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void StartComputations(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr) +{ + XHdcp1x_Cipher *CipherPtr = &InstancePtr->Cipher; + u64 Value = 0; + u32 X = 0; + u32 Y = 0; + u32 Z = 0; + + /* Log */ + DebugLog(InstancePtr, "starting computations"); + + /* Update Value with An */ + Value = InstancePtr->StateHelper; + + /* Load the cipher B registers with An */ + X = (u32) (Value & 0x0FFFFFFFul); + Value >>= 28; + Y = (u32) (Value & 0x0FFFFFFFul); + Value >>= 28; + Z = (u32) (Value & 0x000000FFul); + if ((InstancePtr->Flags & FLAG_IS_REPEATER) != 0) { + Z |= (1ul << 8); + } + XHdcp1x_CipherSetB(CipherPtr, X, Y, Z); + + /* Initiate the block cipher */ + XHdcp1x_CipherDoRequest(CipherPtr, XHDCP1X_CIPHER_REQUEST_BLOCK); +} + +/*****************************************************************************/ +/** +* This function polls the progress of the computations for a state machine. +* +* @param InstancePtr is the HDCP state machine. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void PollForComputations(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr) +{ + /* Check for done */ + if (XHdcp1x_CipherIsRequestComplete(&InstancePtr->Cipher)) { + DebugLog(InstancePtr, "computations complete"); + *NextStatePtr = STATE_VALIDATERX; + } + else { + DebugLog(InstancePtr, "waiting for computations"); + } +} + +/*****************************************************************************/ +/** +* This function validates the attached receiver. +* +* @param InstancePtr is the HDCP state machine. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void ValidateRx(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr) +{ + XHdcp1x_Port *PortPtr = &InstancePtr->Port; + XHdcp1x_Cipher *CipherPtr = &InstancePtr->Cipher; + u8 Buf[2]; + int NumTries = 3; + + /* Update NextStatePtr */ + *NextStatePtr = STATE_UNAUTHENTICATED; + + /* Attempt to read Ro */ + do { + /* Read the remote Ro' */ + if (XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_RO, + Buf, 2) > 0) { + char LogBuf[32]; + u16 RemoteRo = 0; + u16 LocalRo = 0; + + /* Determine RemoteRo */ + XHDCP1X_PORT_BUF_TO_UINT(RemoteRo, Buf, 2 * 8); + + /* Determine theLLocalRoocalRo */ + LocalRo = XHdcp1x_CipherGetRo(CipherPtr); + + /* Compare the Ro values */ + if (LocalRo == RemoteRo) { + + /* Determine theLogBuf */ + snprintf(LogBuf, 32, "rx valid Ro/Ro' (%04X)", + LocalRo); + + /* Update NextStatePtr */ + *NextStatePtr = STATE_TESTFORREPEATER; + } + /* Otherwise */ + else { + /* Determine theLogBuf */ + snprintf(LogBuf, 32, "Ro/Ro' mismatch (%04X/" + "%04X)", LocalRo, RemoteRo); + + /* Update statistics if the last attempt */ + if (NumTries == 1) + InstancePtr->Stats.AuthFailed++; + } + + /* Log */ + DebugLog(InstancePtr, LogBuf); + } + /* Otherwise */ + else { + /* Log */ + DebugLog(InstancePtr, "Ro' read failure"); + + /* Update the statistics */ + InstancePtr->Stats.ReadFailures++; + } + + /* Update for loop */ + NumTries--; + } + while ((*NextStatePtr == STATE_UNAUTHENTICATED) && (NumTries > 0)); +} + +/*****************************************************************************/ +/** +* This function checks the integrity of a HDCP link. +* +* @param InstancePtr is the hdcp state machine. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void CheckLinkIntegrity(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr) +{ + XHdcp1x_Port *PortPtr = &InstancePtr->Port; + XHdcp1x_Cipher *CipherPtr = &InstancePtr->Cipher; + u8 Buf[2]; + int NumTries = 3; + + /* Update theNextState */ + *NextStatePtr = STATE_DETERMINERXCAPABLE; + + /* Iterate through the tries */ + do { + /* Read the remote Ri' */ + if (XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_RO, + Buf, 2) > 0) { + + char LogBuf[48]; + u16 RemoteRi = 0; + u16 LocalRi = 0; + + /* Determine theRemoteRo */ + XHDCP1X_PORT_BUF_TO_UINT(RemoteRi, Buf, 16); + + /* Determine theLocalRi */ + LocalRi = XHdcp1x_CipherGetRi(CipherPtr); + + /* Compare the local and remote values */ + if (LocalRi == RemoteRi) { + *NextStatePtr = STATE_AUTHENTICATED; + snprintf(LogBuf, 48, "link check passed Ri/Ri'" + "(%04X)", LocalRi); + } + /* Check for last attempt */ + else if (NumTries == 1) { + snprintf(LogBuf, 48, "link check failed Ri/Ri'" + "(%04X/%04X)", LocalRi, + RemoteRi); + } + + /* Log */ + DebugLog(InstancePtr, LogBuf); + } + else { + DebugLog(InstancePtr, "Ri' read failure"); + InstancePtr->Stats.ReadFailures++; + } + + /* Update for loop */ + NumTries--; + } + while ((*NextStatePtr != STATE_AUTHENTICATED) && (NumTries > 0)); + + /* Check for success */ + if (*NextStatePtr == STATE_AUTHENTICATED) { + InstancePtr->Stats.LinkCheckPassed++; + } + else { + InstancePtr->Stats.LinkCheckFailed++; + } +} + +/*****************************************************************************/ +/** +* This function checks the remote end to see if its a repeater. +* +* @param InstancePtr is the HDCP state machine. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note The implementation of this function enables encryption when a +* repeater is detected downstream. The standard is ambiguous as to +* the handling of this specific case by this behaviour is required +* in order to pass the Unigraf compliance test suite. +* +******************************************************************************/ +static void TestForRepeater(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr) +{ + XHdcp1x_Port *PortPtr = &InstancePtr->Port; + + /* Check for repeater */ + if (XHdcp1x_PortIsRepeater(PortPtr)) { + u8 Buf[XHDCP1X_PORT_SIZE_AINFO]; + + /* Update InstancePtr */ + InstancePtr->Flags |= FLAG_IS_REPEATER; + + /* Clear AINFO */ + memset(Buf, 0, XHDCP1X_PORT_SIZE_AINFO); + XHdcp1x_PortWrite(PortPtr, XHDCP1X_PORT_OFFSET_AINFO, Buf, + XHDCP1X_PORT_SIZE_AINFO); + + /* Update NextStatePtr */ + *NextStatePtr = STATE_WAITFORREADY; + + /* Log */ + DebugLog(InstancePtr, "repeater detected"); + + /* Enable authentication if needed */ + EnableEncryption(InstancePtr); + } + else { + /* Update InstancePtr */ + InstancePtr->Flags &= ~FLAG_IS_REPEATER; + + /* Update NextStatePtr */ + *NextStatePtr = STATE_AUTHENTICATED; + } +} + +/*****************************************************************************/ +/** +* This function polls a state machine in the "wait for ready" state. +* +* @param InstancePtr is the hdcp state machine. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void PollForWaitForReady(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr) +{ + XHdcp1x_Port *PortPtr = &InstancePtr->Port; + u16 RepeaterInfo = 0; + int Status = XST_SUCCESS; + + /* Attempt to read the repeater info */ + Status = XHdcp1x_PortGetRepeaterInfo(PortPtr, &RepeaterInfo); + if (Status == XST_SUCCESS) { + /* Check that neither cascade or device numbers exceeded */ + if ((RepeaterInfo & 0x0880u) == 0) { + /* Check for at least one attached device */ + if ((RepeaterInfo & 0x007Fu) != 0) { + /* Update InstancePtr */ + InstancePtr->StateHelper = RepeaterInfo; + + /* Update NextStatePtr */ + *NextStatePtr = STATE_READKSVLIST; + + /* Log */ + DebugLog(InstancePtr, "devices attached: " + "ksv list ready"); + } + /* Otherwise */ + else { + /* Update NextStatePtr */ + *NextStatePtr = STATE_AUTHENTICATED; + + /* Log */ + DebugLog(InstancePtr, "no attached devices"); + } + } + /* Check for cascade exceeded */ + else { + /* Update NextStatePtr */ + *NextStatePtr = STATE_UNAUTHENTICATED; + + /* Log */ + if ((RepeaterInfo & 0x0800u) != 0) { + DebugLog(InstancePtr, "max cascade exceeded"); + } + else { + DebugLog(InstancePtr, "max devices exceeded"); + } + } + } +} + +/*****************************************************************************/ +/** +* This function validates the ksv list from an attached repeater. +* +* @param InstancePtr is the hdcp state machine. +* @param RepeaterInfo is the repeater information. +* +* @return Truth value indicating valid (TRUE) or invalid (FALSE). +* +* @note None. +* +******************************************************************************/ +static int ValidateKsvList(XHdcp1x_Tx *InstancePtr, u16 RepeaterInfo) +{ + XHdcp1x_Port *PortPtr = &InstancePtr->Port; + XHdcp1x_Cipher *CipherPtr = &InstancePtr->Cipher; + SHA1Context Sha1Context; + u8 Buf[24]; + int NumToRead = 0; + int IsValid = FALSE; + + /* Initialize Buf */ + memset(Buf, 0, 24); + + /* Initialize Sha1Context */ + SHA1Reset(&Sha1Context); + + /* Assume success */ + IsValid = TRUE; + + /* Determine theNumToRead */ + NumToRead = ((RepeaterInfo & 0x7Fu)*5); + + /* Read the ksv list */ + do { + int NumThisTime = XHDCP1X_PORT_SIZE_KSVFIFO; + + /* Truncate if necessary */ + if (NumThisTime > NumToRead) { + NumThisTime = NumToRead; + } + + /* Read the next chunk of the list */ + if (XHdcp1x_PortRead(PortPtr, XHDCP1X_PORT_OFFSET_KSVFIFO, + Buf, NumThisTime) > 0) { + /* Update the calculation of V */ + SHA1Input(&Sha1Context, Buf, NumThisTime); + } + else { + /* Update the statistics */ + InstancePtr->Stats.ReadFailures++; + + /* Update IsValid */ + IsValid = FALSE; + } + + /* Update for loop */ + NumToRead -= NumThisTime; + } + while ((NumToRead > 0) && (IsValid)); + + /* Check for success */ + if (IsValid) { + u64 Mo = 0; + u8 Sha1Result[SHA1HashSize]; + + /* Insert RepeaterInfo into the SHA-1 transform */ + Buf[0] = (u8) (RepeaterInfo & 0xFFu); + Buf[1] = (u8) ((RepeaterInfo >> 8) & 0xFFu); + SHA1Input(&Sha1Context, Buf, 2); + + /* Insert the Mo into the SHA-1 transform */ + Mo = XHdcp1x_CipherGetMo(CipherPtr); + XHDCP1X_PORT_UINT_TO_BUF(Buf, Mo, 64); + SHA1Input(&Sha1Context, Buf, 8); + + /* Finalize the SHA-1 result and confirm success */ + if (SHA1Result(&Sha1Context, Sha1Result) == shaSuccess) { + u8 Offset = XHDCP1X_PORT_OFFSET_VH0; + const u8 *Sha1Buf = Sha1Result; + int NumIterations = (SHA1HashSize >> 2); + + /* Iterate through the SHA-1 chunks */ + do { + u32 CalcValue = 0; + u32 ReadValue = 0; + + /* Determine CalcValue */ + CalcValue = *Sha1Buf++; + CalcValue <<= 8; + CalcValue |= *Sha1Buf++; + CalcValue <<= 8; + CalcValue |= *Sha1Buf++; + CalcValue <<= 8; + CalcValue |= *Sha1Buf++; + + /* Read the value from the far end */ + if (XHdcp1x_PortRead(PortPtr, Offset, Buf, + 4) > 0) { + /* Determine ReadValue */ + XHDCP1X_PORT_BUF_TO_UINT(ReadValue, + Buf, 32); + } + else { + /* Update ReadValue */ + ReadValue = 0; + + /* Update the statistics */ + InstancePtr->Stats.ReadFailures++; + } + + /* Check for mismatch */ + if (CalcValue != ReadValue) { + IsValid = FALSE; + } + + /* Update for loop */ + Offset += 4; + NumIterations--; + } + while (NumIterations > 0); + } + /* Otherwise */ + else { + IsValid = FALSE; + } + } + + return (IsValid); +} + +/*****************************************************************************/ +/** +* This function reads the ksv list from an attached repeater. +* +* @param InstancePtr is the hdcp state machine. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void ReadKsvList(XHdcp1x_Tx *InstancePtr, tState *NextStatePtr) +{ + int NumAttempts = 3; + int KsvListIsValid = FALSE; + u16 RepeaterInfo = 0; + + /* Determine RepeaterInfo */ + RepeaterInfo = (u16) (InstancePtr->StateHelper & 0x0FFFu); + + /* Iterate through the attempts */ + do { + /* Attempt to validate the ksv list */ + KsvListIsValid = ValidateKsvList(InstancePtr, RepeaterInfo); + + /* Update for loop */ + NumAttempts--; + } + while ((NumAttempts > 0) && (!KsvListIsValid)); + + /* Check for success */ + if (KsvListIsValid) { + /* Log */ + DebugLog(InstancePtr, "ksv list validated"); + + /* Update NextStatePtr */ + *NextStatePtr = STATE_AUTHENTICATED; + } + else { + /* Log */ + DebugLog(InstancePtr, "ksv list invalid"); + + /* Update NextStatePtr */ + *NextStatePtr = STATE_UNAUTHENTICATED; + } +} + +/*****************************************************************************/ +/** +* This function queries a a handler to check if its been authenticated. +* +* @param InstancePtr is the HDCP state machine. +* +* @return Truth value indicating authenticated (true) or not (false) +* +* @note None. +* +******************************************************************************/ +static int IsAuthenticated(const XHdcp1x_Tx *InstancePtr) +{ + int Authenticated = FALSE; + + /* Which state? */ + switch (InstancePtr->CurrentState) { + /* For the authenticated and link integrity check states */ + case STATE_AUTHENTICATED: + case STATE_LINKINTEGRITYCHECK: + Authenticated = TRUE; + break; + + /* Otherwise */ + default: + Authenticated = FALSE; + break; + } + + return (Authenticated); +} + +/*****************************************************************************/ +/** +* This function runs the "disabled" state of the transmit state machine. +* +* @param InstancePtr is the transmitter instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunDisabledState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For enable */ + case EVENT_ENABLE: + *NextStatePtr = STATE_UNAUTHENTICATED; + if ((InstancePtr->Flags & FLAG_PHY_UP) == 0) { + *NextStatePtr = STATE_PHYDOWN; + } + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + InstancePtr->Flags &= ~FLAG_PHY_UP; + break; + + /* For physical layer up */ + case EVENT_PHYUP: + InstancePtr->Flags |= FLAG_PHY_UP; + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "determine rx capable" state of the transmit state +* machine. +* +* @param InstancePtr is the transmitter instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunDetermineRxCapableState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "exchange ksvs" state of the transmit state machine. +* +* @param InstancePtr is the transmitter instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunExchangeKsvsState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "computations" state of the transmit state machine. +* +* @param InstancePtr is the transmitter instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunComputationsState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For authenticate */ + case EVENT_AUTHENTICATE: + *NextStatePtr = STATE_DETERMINERXCAPABLE; + break; + + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* For poll */ + case EVENT_POLL: + PollForComputations(InstancePtr, NextStatePtr); + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "validate-rx" state of the transmit state machine. +* +* @param InstancePtr is the transmitter instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunValidateRxState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For authenticate */ + case EVENT_AUTHENTICATE: + *NextStatePtr = STATE_DETERMINERXCAPABLE; + break; + + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* For timeout */ + case EVENT_TIMEOUT: + DebugLog(InstancePtr, "validate-rx timeout"); + ValidateRx(InstancePtr, NextStatePtr); + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "authenticated" state of the transmit state machine. +* +* @param InstancePtr is the transmitter instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunAuthenticatedState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For authenticate */ + case EVENT_AUTHENTICATE: + *NextStatePtr = STATE_DETERMINERXCAPABLE; + break; + + /* For check */ + case EVENT_CHECK: + *NextStatePtr = STATE_LINKINTEGRITYCHECK; + break; + + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "link-integrity check" state of the transmit state +* machine. +* +* @param InstancePtr is the transmitter instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunLinkIntegrityCheckState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For authenticate */ + case EVENT_AUTHENTICATE: + *NextStatePtr = STATE_DETERMINERXCAPABLE; + break; + + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* For poll */ + case EVENT_POLL: + CheckLinkIntegrity(InstancePtr, NextStatePtr); + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "test-for-repeater" state of the transmit state +* machine. +* +* @param InstancePtr is the transmitter instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunTestForRepeaterState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For authenticate */ + case EVENT_AUTHENTICATE: + *NextStatePtr = STATE_DETERMINERXCAPABLE; + break; + + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* For poll */ + case EVENT_POLL: + TestForRepeater(InstancePtr, NextStatePtr); + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "wait-for-ready" state of the transmit state machine. +* +* @param InstancePtr is the transmitter instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunWaitForReadyState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For authenticate */ + case EVENT_AUTHENTICATE: + *NextStatePtr = STATE_DETERMINERXCAPABLE; + break; + + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* For poll */ + case EVENT_POLL: + PollForWaitForReady(InstancePtr, NextStatePtr); + break; + + /* For timeout */ + case EVENT_TIMEOUT: + DebugLog(InstancePtr, "wait-for-ready timeout"); + PollForWaitForReady(InstancePtr, NextStatePtr); + if (*NextStatePtr == STATE_WAITFORREADY) { + *NextStatePtr = STATE_UNAUTHENTICATED; + } + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "read-ksv-list" state of the transmit state machine. +* +* @param InstancePtr is the transmitter instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunReadKsvListState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For authenticate */ + case EVENT_AUTHENTICATE: + *NextStatePtr = STATE_DETERMINERXCAPABLE; + break; + + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function runs the "unauthenticated" state of the transmit state machine. +* +* @param InstancePtr is the transmitter instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunUnauthenticatedState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For authenticate */ + case EVENT_AUTHENTICATE: + *NextStatePtr = STATE_DETERMINERXCAPABLE; + break; + + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer down */ + case EVENT_PHYDOWN: + *NextStatePtr = STATE_PHYDOWN; + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + + +/*****************************************************************************/ +/** +* This function runs the "physical-layer-down" state of the transmit state +* machine. +* +* @param InstancePtr is the transmitter instance. +* @param Event is the event to process. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void RunPhysicalLayerDownState(XHdcp1x_Tx *InstancePtr, tEvent Event, + tState *NextStatePtr) +{ + /* Which event? */ + switch (Event) { + /* For disable */ + case EVENT_DISABLE: + *NextStatePtr = STATE_DISABLED; + break; + + /* For physical layer up */ + case EVENT_PHYUP: + *NextStatePtr = STATE_UNAUTHENTICATED; + if (InstancePtr->EncryptionMap != 0) { + PostEvent(InstancePtr, EVENT_AUTHENTICATE); + } + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function enters a state. +* +* @param InstancePtr is the HDCP state machine. +* @param State is the state to enter. +* @param NextStatePtr is the next state. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void EnterState(XHdcp1x_Tx *InstancePtr, tState State, + tState *NextStatePtr) +{ + /* Which state? */ + switch (State) { + /* For the disabled state */ + case STATE_DISABLED: + Disable(InstancePtr); + break; + + /* For determine rx capable */ + case STATE_DETERMINERXCAPABLE: + InstancePtr->Flags |= FLAG_PHY_UP; + SetCheckLinkState(InstancePtr, FALSE); + DisableEncryption(InstancePtr); + CheckRxCapable(InstancePtr, NextStatePtr); + break; + + /* For the exchange ksvs state */ + case STATE_EXCHANGEKSVS: + InstancePtr->StateHelper = 0; + ExchangeKsvs(InstancePtr, NextStatePtr); + break; + + /* For the computations state */ + case STATE_COMPUTATIONS: + StartComputations(InstancePtr, NextStatePtr); + break; + + /* For the validate rx state */ + case STATE_VALIDATERX: + InstancePtr->StateHelper = 0; + StartTimer(InstancePtr, TMO_100MS); + break; + + /* For the wait for ready state */ + case STATE_WAITFORREADY: + InstancePtr->StateHelper = 0; + StartTimer(InstancePtr, (5 * TMO_1SECOND)); + break; + + /* For the read ksv list state */ + case STATE_READKSVLIST: + ReadKsvList(InstancePtr, NextStatePtr); + break; + + /* For the authenticated state */ + case STATE_AUTHENTICATED: + InstancePtr->StateHelper = 0; + EnableEncryption(InstancePtr); + if (InstancePtr->PreviousState != + STATE_LINKINTEGRITYCHECK) { + InstancePtr->Stats.AuthPassed++; + SetCheckLinkState(InstancePtr, TRUE); + DebugLog(InstancePtr, "authenticated"); + } + break; + + /* For the link integrity check state */ + case STATE_LINKINTEGRITYCHECK: + CheckLinkIntegrity(InstancePtr, NextStatePtr); + break; + + /* For the unauthenticated state */ + case STATE_UNAUTHENTICATED: + InstancePtr->Flags &= ~FLAG_IS_REPEATER; + InstancePtr->Flags |= FLAG_PHY_UP; + DisableEncryption(InstancePtr); + break; + + /* For physical layer down */ + case STATE_PHYDOWN: + InstancePtr->Flags &= ~FLAG_PHY_UP; + DisableEncryption(InstancePtr); + XHdcp1x_CipherDisable(&InstancePtr->Cipher); + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function exits a state. +* +* @param InstancePtr is the HDCP state machine. +* @param State is the state to exit. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void ExitState(XHdcp1x_Tx *InstancePtr, tState State) +{ + /* Which state? */ + switch (State) { + /* For the disabled state */ + case STATE_DISABLED: + Enable(InstancePtr); + break; + + /* For the computations state */ + case STATE_COMPUTATIONS: + InstancePtr->StateHelper = 0; + break; + + /* For the validate rx state */ + case STATE_VALIDATERX: + StopTimer(InstancePtr); + break; + + /* For the wait for ready state */ + case STATE_WAITFORREADY: + StopTimer(InstancePtr); + break; + + /* For the read ksv list state */ + case STATE_READKSVLIST: + InstancePtr->StateHelper = 0; + break; + + /* For physical layer down */ + case STATE_PHYDOWN: + XHdcp1x_CipherEnable(&InstancePtr->Cipher); + break; + + /* Otherwise */ + default: + /* Do nothing */ + break; + } +} + +/*****************************************************************************/ +/** +* This function drives a transmit state machine. +* +* @param InstancePtr is the HDCP state machine. +* @param Event is the event to process. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void DoTheState(XHdcp1x_Tx *InstancePtr, tEvent Event) +{ + tState NextState = InstancePtr->CurrentState; + + /* Which state? */ + switch (InstancePtr->CurrentState) { + /* For the disabled state */ + case STATE_DISABLED: + RunDisabledState(InstancePtr, Event, &NextState); + break; + + /* For determine rx capable state */ + case STATE_DETERMINERXCAPABLE: + RunDetermineRxCapableState(InstancePtr, Event, + &NextState); + break; + + /* For exchange ksvs state */ + case STATE_EXCHANGEKSVS: + RunExchangeKsvsState(InstancePtr, Event, &NextState); + break; + + /* For the computations state */ + case STATE_COMPUTATIONS: + RunComputationsState(InstancePtr, Event, &NextState); + break; + + /* For the validate rx state */ + case STATE_VALIDATERX: + RunValidateRxState(InstancePtr, Event, &NextState); + break; + + /* For the authenticated state */ + case STATE_AUTHENTICATED: + RunAuthenticatedState(InstancePtr, Event, &NextState); + break; + + /* For the link integrity check state */ + case STATE_LINKINTEGRITYCHECK: + RunLinkIntegrityCheckState(InstancePtr, Event, + &NextState); + break; + + /* For the test for repeater state */ + case STATE_TESTFORREPEATER: + RunTestForRepeaterState(InstancePtr, Event, &NextState); + break; + + /* For the wait for ready state */ + case STATE_WAITFORREADY: + RunWaitForReadyState(InstancePtr, Event, &NextState); + break; + + /* For the reads ksv list state */ + case STATE_READKSVLIST: + RunReadKsvListState(InstancePtr, Event, &NextState); + break; + + /* For the unauthenticated state */ + case STATE_UNAUTHENTICATED: + RunUnauthenticatedState(InstancePtr, Event, &NextState); + break; + + /* For the physical layer down state */ + case STATE_PHYDOWN: + RunPhysicalLayerDownState(InstancePtr, Event, + &NextState); + break; + + /* Otherwise */ + default: + break; + } + + /* Check for state change */ + while (InstancePtr->CurrentState != NextState) { + /* Perform the state transition */ + ExitState(InstancePtr, InstancePtr->CurrentState); + InstancePtr->PreviousState = InstancePtr->CurrentState; + InstancePtr->CurrentState = NextState; + EnterState(InstancePtr, InstancePtr->CurrentState, &NextState); + } +} + +/*****************************************************************************/ +/** +* This function initializes a transmit state machine. +* +* @param InstancePtr is the receiver instance. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void Init(XHdcp1x_Tx *InstancePtr) +{ + tState DummyState = STATE_DISABLED; + + /* Update theHandler */ + InstancePtr->PendingEvents = 0; + + /* Kick the state machine */ + EnterState(InstancePtr, STATE_DISABLED, &DummyState); +} + +/*****************************************************************************/ +/** +* This function processes the events pending on a state machine. +* +* @param InstancePtr is the receiver instance. +* +* @return None. +* +* @note None. +* +******************************************************************************/ +static void ProcessPending(XHdcp1x_Tx *InstancePtr) +{ + /* Check for any pending events */ + if (InstancePtr->PendingEvents != 0) { + u16 Pending = InstancePtr->PendingEvents; + tEvent Event = EVENT_NULL; + + /* Update InstancePtr */ + InstancePtr->PendingEvents = 0; + + /* Iterate through thePending */ + do { + /* Check for a pending event */ + if ((Pending & 1u) != 0) { + DoTheState(InstancePtr, Event); + } + + /* Update for loop */ + Pending >>= 1; + Event++; + } + while (Pending != 0); + } +} + +/*****************************************************************************/ +/** +* This function converts from a state to a display string. +* +* @param State is the state to convert. +* +* @return The corresponding display string. +* +* @note None. +* +******************************************************************************/ +static const char *StateToString(tState State) +{ + const char *String = NULL; + + /* Which state? */ + switch (State) { + case STATE_DISABLED: + String = "disabled"; + break; + + case STATE_DETERMINERXCAPABLE: + String = "determine-rx-capable"; + break; + + case STATE_EXCHANGEKSVS: + String = "exchange-ksvs"; + break; + + case STATE_COMPUTATIONS: + String = "computations"; + break; + + case STATE_VALIDATERX: + String = "validate-rx"; + break; + + case STATE_AUTHENTICATED: + String = "authenticated"; + break; + + case STATE_LINKINTEGRITYCHECK: + String = "link-integrity-check"; + break; + + case STATE_TESTFORREPEATER: + String = "test-for-repeater"; + break; + + case STATE_WAITFORREADY: + String = "wait-for-ready"; + break; + + case STATE_READKSVLIST: + String = "read-ksv-list"; + break; + + case STATE_UNAUTHENTICATED: + String = "unauthenticated"; + break; + + case STATE_PHYDOWN: + String = "physical-layer-down"; + break; + + default: + String = "???"; + break; + } + + return (String); +} diff --git a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_tx.h b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_tx.h index b12743ec..3765f1f3 100644 --- a/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_tx.h +++ b/XilinxProcessorIPLib/drivers/hdcp1x/src/xhdcp1x_tx.h @@ -18,8 +18,8 @@ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* XILINX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. @@ -41,10 +41,11 @@ * * Ver Who Date Changes * ----- ------ -------- -------------------------------------------------- -* 1.00 07/16/15 Initial release. +* 1.00 fidus 07/16/15 Initial release. * * ******************************************************************************/ + #ifndef XHDCP1X_TX_H /**< Prevent circular inclusions by using protection macros */ #define XHDCP1X_TX_H @@ -54,6 +55,7 @@ extern "C" { #endif /***************************** Include Files *********************************/ + #include "xhdcp1x.h" #include "xparameters.h" #include "xstatus.h" @@ -66,6 +68,7 @@ extern "C" { /***************** Macros (Inline Functions) Definitions *********************/ /************************** Function Prototypes ******************************/ + int XHdcp1x_TxCfgInitialize(XHdcp1x_Tx *InstancePtr, const XHdcp1x_Config *CfgPtr, void *PhyIfPtr);