1 /* 2 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <cdefs.h> 8 #include <cdn_dp.h> 9 #include <smccc.h> 10 #include <stdlib.h> 11 #include <string.h> 12 13 __asm__( 14 ".pushsection .text.hdcp_handler, \"ax\", %progbits\n" 15 ".global hdcp_handler\n" 16 ".balign 4\n" 17 "hdcp_handler:\n" 18 ".incbin \"" __XSTRING(HDCPFW) "\"\n" 19 ".type hdcp_handler, %function\n" 20 ".size hdcp_handler, .- hdcp_handler\n" 21 ".popsection\n" 22 ); 23 24 static uint64_t *hdcp_key_pdata; 25 static struct cdn_dp_hdcp_key_1x key; 26 27 int hdcp_handler(struct cdn_dp_hdcp_key_1x *key); 28 29 uint64_t dp_hdcp_ctrl(uint64_t type) 30 { 31 switch (type) { 32 case HDCP_KEY_DATA_START_TRANSFER: 33 memset(&key, 0x00, sizeof(key)); 34 hdcp_key_pdata = (uint64_t *)&key; 35 return 0; 36 case HDCP_KEY_DATA_START_DECRYPT: 37 if (hdcp_key_pdata == (uint64_t *)(&key + 1)) 38 return hdcp_handler(&key); 39 else 40 return PSCI_E_INVALID_PARAMS; 41 default: 42 return SMC_UNK; 43 } 44 } 45 46 uint64_t dp_hdcp_store_key(uint64_t x1, 47 uint64_t x2, 48 uint64_t x3, 49 uint64_t x4, 50 uint64_t x5, 51 uint64_t x6) 52 { 53 if (hdcp_key_pdata < (uint64_t *)&key || 54 hdcp_key_pdata + 6 > (uint64_t *)(&key + 1)) 55 return PSCI_E_INVALID_PARAMS; 56 57 hdcp_key_pdata[0] = x1; 58 hdcp_key_pdata[1] = x2; 59 hdcp_key_pdata[2] = x3; 60 hdcp_key_pdata[3] = x4; 61 hdcp_key_pdata[4] = x5; 62 hdcp_key_pdata[5] = x6; 63 hdcp_key_pdata += 6; 64 65 return 0; 66 } 67