developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 5 | */ |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 6 | |
| 7 | #include <common/debug.h> |
| 8 | #include <common/runtime_svc.h> |
| 9 | #include <lib/mmio.h> |
| 10 | |
developer | eee2980 | 2016-05-11 18:45:20 +0800 | [diff] [blame] | 11 | #include <crypt.h> |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 12 | #include <mtcmos.h> |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 13 | #include <mtk_sip_svc.h> |
developer | 73b982f | 2016-05-11 18:04:09 +0800 | [diff] [blame] | 14 | #include <plat_sip_calls.h> |
developer | 65014b8 | 2015-04-13 14:47:57 +0800 | [diff] [blame] | 15 | |
| 16 | /* Authorized secure register list */ |
| 17 | enum { |
| 18 | SREG_HDMI_COLOR_EN = 0x14000904 |
| 19 | }; |
| 20 | |
| 21 | static const uint32_t authorized_sreg[] = { |
| 22 | SREG_HDMI_COLOR_EN |
| 23 | }; |
| 24 | |
| 25 | #define authorized_sreg_cnt \ |
| 26 | (sizeof(authorized_sreg) / sizeof(authorized_sreg[0])) |
| 27 | |
| 28 | uint64_t mt_sip_set_authorized_sreg(uint32_t sreg, uint32_t val) |
| 29 | { |
| 30 | uint64_t i; |
| 31 | |
| 32 | for (i = 0; i < authorized_sreg_cnt; i++) { |
| 33 | if (authorized_sreg[i] == sreg) { |
| 34 | mmio_write_32(sreg, val); |
| 35 | return MTK_SIP_E_SUCCESS; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | return MTK_SIP_E_INVALID_PARAM; |
| 40 | } |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 41 | |
developer | 73b982f | 2016-05-11 18:04:09 +0800 | [diff] [blame] | 42 | static uint64_t mt_sip_pwr_on_mtcmos(uint32_t val) |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 43 | { |
| 44 | uint32_t ret; |
| 45 | |
| 46 | ret = mtcmos_non_cpu_ctrl(1, val); |
| 47 | if (ret) |
| 48 | return MTK_SIP_E_INVALID_PARAM; |
| 49 | else |
| 50 | return MTK_SIP_E_SUCCESS; |
| 51 | } |
| 52 | |
developer | 73b982f | 2016-05-11 18:04:09 +0800 | [diff] [blame] | 53 | static uint64_t mt_sip_pwr_off_mtcmos(uint32_t val) |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 54 | { |
| 55 | uint32_t ret; |
| 56 | |
| 57 | ret = mtcmos_non_cpu_ctrl(0, val); |
| 58 | if (ret) |
| 59 | return MTK_SIP_E_INVALID_PARAM; |
| 60 | else |
| 61 | return MTK_SIP_E_SUCCESS; |
| 62 | } |
| 63 | |
developer | 73b982f | 2016-05-11 18:04:09 +0800 | [diff] [blame] | 64 | static uint64_t mt_sip_pwr_mtcmos_support(void) |
developer | b8925a2 | 2015-11-16 14:38:40 +0800 | [diff] [blame] | 65 | { |
| 66 | return MTK_SIP_E_SUCCESS; |
| 67 | } |
developer | 73b982f | 2016-05-11 18:04:09 +0800 | [diff] [blame] | 68 | |
| 69 | uint64_t mediatek_plat_sip_handler(uint32_t smc_fid, |
| 70 | uint64_t x1, |
| 71 | uint64_t x2, |
| 72 | uint64_t x3, |
| 73 | uint64_t x4, |
| 74 | void *cookie, |
| 75 | void *handle, |
| 76 | uint64_t flags) |
| 77 | { |
| 78 | uint64_t ret; |
| 79 | |
| 80 | switch (smc_fid) { |
| 81 | case MTK_SIP_PWR_ON_MTCMOS: |
| 82 | ret = mt_sip_pwr_on_mtcmos((uint32_t)x1); |
| 83 | SMC_RET1(handle, ret); |
| 84 | |
| 85 | case MTK_SIP_PWR_OFF_MTCMOS: |
| 86 | ret = mt_sip_pwr_off_mtcmos((uint32_t)x1); |
| 87 | SMC_RET1(handle, ret); |
| 88 | |
| 89 | case MTK_SIP_PWR_MTCMOS_SUPPORT: |
| 90 | ret = mt_sip_pwr_mtcmos_support(); |
| 91 | SMC_RET1(handle, ret); |
| 92 | |
developer | eee2980 | 2016-05-11 18:45:20 +0800 | [diff] [blame] | 93 | case MTK_SIP_SET_HDCP_KEY_EX: |
| 94 | ret = crypt_set_hdcp_key_ex(x1, x2, x3); |
| 95 | SMC_RET1(handle, ret); |
| 96 | |
| 97 | case MTK_SIP_SET_HDCP_KEY_NUM: |
| 98 | ret = crypt_set_hdcp_key_num((uint32_t)x1); |
| 99 | SMC_RET1(handle, ret); |
| 100 | |
| 101 | case MTK_SIP_CLR_HDCP_KEY: |
| 102 | ret = crypt_clear_hdcp_key(); |
| 103 | SMC_RET1(handle, ret); |
| 104 | |
developer | 73b982f | 2016-05-11 18:04:09 +0800 | [diff] [blame] | 105 | default: |
| 106 | ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); |
| 107 | break; |
| 108 | } |
| 109 | |
| 110 | SMC_RET1(handle, SMC_UNK); |
| 111 | } |