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