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