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 | |
Ziyuan Xu | 4060cfd | 2017-02-10 11:54:52 +0800 | [diff] [blame] | 7 | #include <cdn_dp.h> |
Antonio Nino Diaz | 3c817f4 | 2018-03-21 10:49:27 +0000 | [diff] [blame] | 8 | #include <smccc.h> |
Ziyuan Xu | 48890e2 | 2016-10-27 19:07:35 +0800 | [diff] [blame] | 9 | #include <stdlib.h> |
Ziyuan Xu | 4060cfd | 2017-02-10 11:54:52 +0800 | [diff] [blame] | 10 | #include <string.h> |
Ziyuan Xu | 48890e2 | 2016-10-27 19:07:35 +0800 | [diff] [blame] | 11 | |
| 12 | __asm__( |
| 13 | ".pushsection .text.hdcp_handler, \"ax\", %progbits\n" |
| 14 | ".global hdcp_handler\n" |
| 15 | ".balign 4\n" |
| 16 | "hdcp_handler:\n" |
| 17 | ".incbin \"" __XSTRING(HDCPFW) "\"\n" |
| 18 | ".type hdcp_handler, %function\n" |
| 19 | ".size hdcp_handler, .- hdcp_handler\n" |
| 20 | ".popsection\n" |
| 21 | ); |
| 22 | |
Ziyuan Xu | 4060cfd | 2017-02-10 11:54:52 +0800 | [diff] [blame] | 23 | static uint64_t *hdcp_key_pdata; |
| 24 | static struct cdn_dp_hdcp_key_1x key; |
| 25 | |
| 26 | int hdcp_handler(struct cdn_dp_hdcp_key_1x *key); |
| 27 | |
| 28 | uint64_t dp_hdcp_ctrl(uint64_t type) |
| 29 | { |
| 30 | switch (type) { |
| 31 | case HDCP_KEY_DATA_START_TRANSFER: |
| 32 | memset(&key, 0x00, sizeof(key)); |
| 33 | hdcp_key_pdata = (uint64_t *)&key; |
| 34 | return 0; |
| 35 | case HDCP_KEY_DATA_START_DECRYPT: |
| 36 | if (hdcp_key_pdata == (uint64_t *)(&key + 1)) |
| 37 | return hdcp_handler(&key); |
| 38 | else |
| 39 | return PSCI_E_INVALID_PARAMS; |
| 40 | default: |
| 41 | return SMC_UNK; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | uint64_t dp_hdcp_store_key(uint64_t x1, |
| 46 | uint64_t x2, |
| 47 | uint64_t x3, |
| 48 | uint64_t x4, |
| 49 | uint64_t x5, |
| 50 | uint64_t x6) |
| 51 | { |
| 52 | if (hdcp_key_pdata < (uint64_t *)&key || |
| 53 | hdcp_key_pdata + 6 > (uint64_t *)(&key + 1)) |
| 54 | return PSCI_E_INVALID_PARAMS; |
| 55 | |
| 56 | hdcp_key_pdata[0] = x1; |
| 57 | hdcp_key_pdata[1] = x2; |
| 58 | hdcp_key_pdata[2] = x3; |
| 59 | hdcp_key_pdata[3] = x4; |
| 60 | hdcp_key_pdata[4] = x5; |
| 61 | hdcp_key_pdata[5] = x6; |
| 62 | hdcp_key_pdata += 6; |
| 63 | |
| 64 | return 0; |
| 65 | } |