rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* Copyright Statement: |
| 2 | * |
| 3 | * This software/firmware and related documentation ("MediaTek Software") are |
| 4 | * protected under relevant copyright laws. The information contained herein is |
| 5 | * confidential and proprietary to MediaTek Inc. and/or its licensors. Without |
| 6 | * the prior written permission of MediaTek inc. and/or its licensors, any |
| 7 | * reproduction, modification, use or disclosure of MediaTek Software, and |
| 8 | * information contained herein, in whole or in part, shall be strictly |
| 9 | * prohibited. |
| 10 | * |
| 11 | * MediaTek Inc. (C) 2017. All rights reserved. |
| 12 | * |
| 13 | * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 14 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 15 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER |
| 16 | * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL |
| 17 | * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED |
| 18 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR |
| 19 | * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH |
| 20 | * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, |
| 21 | * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES |
| 22 | * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. |
| 23 | * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO |
| 24 | * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK |
| 25 | * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE |
| 26 | * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR |
| 27 | * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S |
| 28 | * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE |
| 29 | * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE |
| 30 | * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE |
| 31 | * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 32 | * |
| 33 | * The following software/firmware and/or related documentation ("MediaTek |
| 34 | * Software") have been modified by MediaTek Inc. All revisions are subject to |
| 35 | * any receiver's applicable license agreements with MediaTek Inc. |
| 36 | */ |
| 37 | |
| 38 | #ifndef DEVICE_APC_H |
| 39 | #define DEVICE_APC_H |
| 40 | |
| 41 | #include "typedefs.h" |
| 42 | |
| 43 | #define DEVAPC_AO_INFRA_BASE 0x1000E000 // for INFRA/PERI |
| 44 | #define DEVAPC_AO_MD_BASE 0x10019000 // for MD |
| 45 | #define DEVAPC_AO_MM_BASE 0x1001C000 // for MM |
| 46 | |
| 47 | /******************************************************************************* |
| 48 | * REGISTER ADDRESS DEFINATION |
| 49 | ******************************************************************************/ |
| 50 | /* Device APC AO for INFRA/PERI */ |
| 51 | |
| 52 | #define DEVAPC_AO_INFRA_MAS_DOM_0 ((volatile unsigned int*)(DEVAPC_AO_INFRA_BASE+0x0A00)) |
| 53 | #define DEVAPC_AO_INFRA_MAS_DOM_1 ((volatile unsigned int*)(DEVAPC_AO_INFRA_BASE+0x0A04)) |
| 54 | #define DEVAPC_AO_INFRA_MAS_DOM_2 ((volatile unsigned int*)(DEVAPC_AO_INFRA_BASE+0x0A08)) |
| 55 | #define DEVAPC_AO_INFRA_MAS_DOM_3 ((volatile unsigned int*)(DEVAPC_AO_INFRA_BASE+0x0A0C)) |
| 56 | |
| 57 | #define DEVAPC_AO_INFRA_MAS_SEC_0 ((volatile unsigned int*)(DEVAPC_AO_INFRA_BASE+0x0B00)) |
| 58 | |
| 59 | #define DEVAPC_AO_INFRA_DOM_RMP_0 ((volatile unsigned int*)(DEVAPC_AO_INFRA_BASE+0x0D00)) |
| 60 | #define DEVAPC_AO_INFRA_DOM_RMP_1 ((volatile unsigned int*)(DEVAPC_AO_INFRA_BASE+0x0D04)) |
| 61 | |
| 62 | #define DEVAPC_AO_INFRA_APC_CON ((volatile unsigned int*)(DEVAPC_AO_INFRA_BASE+0x0F00)) |
| 63 | |
| 64 | /* ---------------------------------------------------------------------------------------- */ |
| 65 | /* Device APC AO for MD */ |
| 66 | |
| 67 | #define DEVAPC_AO_MD_DOM_RMP_0 ((volatile unsigned int*)(DEVAPC_AO_MD_BASE+0x0D00)) |
| 68 | |
| 69 | #define DEVAPC_AO_MD_APC_CON ((volatile unsigned int*)(DEVAPC_AO_MD_BASE+0x0F00)) |
| 70 | |
| 71 | /* ---------------------------------------------------------------------------------------- */ |
| 72 | /* Device APC AO for MM */ |
| 73 | |
| 74 | #define DEVAPC_AO_MM_DOM_RMP_0 ((volatile unsigned int*)(DEVAPC_AO_MM_BASE+0x0D00)) |
| 75 | |
| 76 | #define DEVAPC_AO_MM_APC_CON ((volatile unsigned int*)(DEVAPC_AO_MM_BASE+0x0F00)) |
| 77 | |
| 78 | /* ---------------------------------------------------------------------------------------- */ |
| 79 | |
| 80 | #define MOD_NO_IN_1_DEVAPC 16 |
| 81 | #define MASTER_NUM_INFRA 30 |
| 82 | |
| 83 | typedef enum { |
| 84 | NON_SECURE_TRAN = 0, |
| 85 | SECURE_TRAN |
| 86 | } E_TRANSACTION; |
| 87 | |
| 88 | typedef enum { |
| 89 | MASTER_TYPE_INFRA = 0, |
| 90 | } E_MASTER_TYPE; |
| 91 | |
| 92 | typedef enum { |
| 93 | DOMAIN_0 = 0, |
| 94 | DOMAIN_1, |
| 95 | DOMAIN_2, |
| 96 | DOMAIN_3, |
| 97 | DOMAIN_4, |
| 98 | DOMAIN_5, |
| 99 | DOMAIN_6, |
| 100 | DOMAIN_7, |
| 101 | DOMAIN_8, |
| 102 | DOMAIN_9, |
| 103 | DOMAIN_10, |
| 104 | DOMAIN_11, |
| 105 | DOMAIN_12, |
| 106 | DOMAIN_13, |
| 107 | DOMAIN_14, |
| 108 | DOMAIN_15, |
| 109 | DOMAIN_MAX, |
| 110 | } E_DOMAIN; |
| 111 | |
| 112 | /* Masks for Domain Control for DEVAPC */ |
| 113 | #define CONN2AP (0xF << 24) |
| 114 | |
| 115 | |
| 116 | |
| 117 | static inline unsigned int uffs(unsigned int x) |
| 118 | { |
| 119 | unsigned int r = 1; |
| 120 | |
| 121 | if (!x) |
| 122 | return 0; |
| 123 | if (!(x & 0xffff)) { |
| 124 | x >>= 16; |
| 125 | r += 16; |
| 126 | } |
| 127 | if (!(x & 0xff)) { |
| 128 | x >>= 8; |
| 129 | r += 8; |
| 130 | } |
| 131 | if (!(x & 0xf)) { |
| 132 | x >>= 4; |
| 133 | r += 4; |
| 134 | } |
| 135 | if (!(x & 3)) { |
| 136 | x >>= 2; |
| 137 | r += 2; |
| 138 | } |
| 139 | if (!(x & 1)) { |
| 140 | x >>= 1; |
| 141 | r += 1; |
| 142 | } |
| 143 | return r; |
| 144 | } |
| 145 | |
| 146 | #define reg_read32(reg) (*(volatile u32* const)(reg)) |
| 147 | #define reg_write32(reg,val) ((*(volatile u32* const)(reg)) = (val)) |
| 148 | |
| 149 | #define reg_set_bits(reg,bs) ((*(volatile u32*)(reg)) |= (u32)(bs)) |
| 150 | #define reg_clr_bits(reg,bs) ((*(volatile u32*)(reg)) &= ~((u32)(bs))) |
| 151 | |
| 152 | #define reg_set_field(reg,field,val) \ |
| 153 | do { \ |
| 154 | volatile unsigned int tv = reg_read32(reg); \ |
| 155 | tv &= ~(field); \ |
| 156 | tv |= ((val) << (uffs((unsigned int)field) - 1)); \ |
| 157 | reg_write32(reg,tv); \ |
| 158 | } while(0) |
| 159 | |
| 160 | #define reg_get_field(reg,field,val) \ |
| 161 | do { \ |
| 162 | volatile unsigned int tv = reg_read32(reg); \ |
| 163 | val = ((tv & (field)) >> (uffs((unsigned int)field) - 1)); \ |
| 164 | } while(0) |
| 165 | |
| 166 | |
| 167 | void tz_dapc_sec_init(void); |
| 168 | void tz_dapc_sec_postinit(void); |
| 169 | #endif |