Ziyuan Xu | 48890e2 | 2016-10-27 19:07:35 +0800 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
Ziyuan Xu | 48890e2 | 2016-10-27 19:07:35 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 7 | #include <cdefs.h> |
Ziyuan Xu | 4060cfd | 2017-02-10 11:54:52 +0800 | [diff] [blame] | 8 | #include <cdn_dp.h> |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 9 | #include <smccc.h> |
Ziyuan Xu | 48890e2 | 2016-10-27 19:07:35 +0800 | [diff] [blame] | 10 | #include <stdlib.h> |
Ziyuan Xu | 4060cfd | 2017-02-10 11:54:52 +0800 | [diff] [blame] | 11 | #include <string.h> |
Ziyuan Xu | 48890e2 | 2016-10-27 19:07:35 +0800 | [diff] [blame] | 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 | |
Ziyuan Xu | 4060cfd | 2017-02-10 11:54:52 +0800 | [diff] [blame] | 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 | } |