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 | /* DEVAPC = "DEVAPC" |
| 44 | * DEVAPC0 = "DEVAPC_AO_INFRA_PERI" |
| 45 | * DEVAPC1 = "DEVAPC_AO_MM" |
| 46 | */ |
| 47 | |
| 48 | #define DEVAPC_BASE (0x10207000U) |
| 49 | #define DEVAPC0_BASE (0x1000E000U) |
| 50 | #define DEVAPC1_BASE (0x1001C000U) |
| 51 | |
| 52 | /******************************************************************************* |
| 53 | * REGISTER ADDRESS DEFINATION |
| 54 | ******************************************************************************/ |
| 55 | #define PERM_OFF(x) (0x4 * x) |
| 56 | |
| 57 | /* DEVAPC_AO_INFRA_PERI */ |
| 58 | #define DEVAPC0_D0_APC(n) ((volatile unsigned int*)(DEVAPC0_BASE+0x0000+PERM_OFF(n))) |
| 59 | #define DEVAPC0_D1_APC(n) ((volatile unsigned int*)(DEVAPC0_BASE+0x0100+PERM_OFF(n))) |
| 60 | #define DEVAPC0_D2_APC(n) ((volatile unsigned int*)(DEVAPC0_BASE+0x0200+PERM_OFF(n))) |
| 61 | #define DEVAPC0_D3_APC(n) ((volatile unsigned int*)(DEVAPC0_BASE+0x0300+PERM_OFF(n))) |
| 62 | #define DEVAPC0_D4_APC(n) ((volatile unsigned int*)(DEVAPC0_BASE+0x0400+PERM_OFF(n))) |
| 63 | #define DEVAPC0_D5_APC(n) ((volatile unsigned int*)(DEVAPC0_BASE+0x0500+PERM_OFF(n))) |
| 64 | #define DEVAPC0_D6_APC(n) ((volatile unsigned int*)(DEVAPC0_BASE+0x0600+PERM_OFF(n))) |
| 65 | #define DEVAPC0_D7_APC(n) ((volatile unsigned int*)(DEVAPC0_BASE+0x0700+PERM_OFF(n))) |
| 66 | |
| 67 | #define DEVAPC0_APC_CON ((volatile unsigned int*)(DEVAPC0_BASE+0x0F00)) |
| 68 | #define DEVAPC0_MAS_DOM_0 ((volatile unsigned int*)(DEVAPC0_BASE+0x0A00)) |
| 69 | #define DEVAPC0_MAS_DOM_1 ((volatile unsigned int*)(DEVAPC0_BASE+0x0A04)) |
| 70 | #define DEVAPC0_MAS_DOM_2 ((volatile unsigned int*)(DEVAPC0_BASE+0x0A08)) |
| 71 | #define DEVAPC0_MAS_SEC_0 ((volatile unsigned int*)(DEVAPC0_BASE+0x0B00)) |
| 72 | |
| 73 | /* DEVAPC_AO_MM */ |
| 74 | #define DEVAPC1_APC_CON ((volatile unsigned int*)(DEVAPC1_BASE+0x0F00)) |
| 75 | |
| 76 | /* DEVAPC */ |
| 77 | #define DEVAPC_APC_CON ((volatile unsigned int*)(DEVAPC_BASE+0x0F00)) |
| 78 | |
| 79 | |
| 80 | typedef enum { |
| 81 | NS_TRANSACTION = 0, |
| 82 | S_TRANSACTION, |
| 83 | } E_TRANSACTION; |
| 84 | |
| 85 | typedef enum { |
| 86 | DOMAIN_0 = 0, |
| 87 | DOMAIN_1, |
| 88 | DOMAIN_2, |
| 89 | DOMAIN_3, |
| 90 | DOMAIN_4, |
| 91 | DOMAIN_5, |
| 92 | DOMAIN_6, |
| 93 | DOMAIN_7, |
| 94 | } E_DOMAIN; |
| 95 | |
| 96 | typedef enum { |
| 97 | NO_PROTECTION = 0, |
| 98 | SEC_RW_ONLY, |
| 99 | SEC_RW_NSEC_R, |
| 100 | NOT_ACCESSIBLE, |
| 101 | } E_SLAVE_PERMISSION; |
| 102 | |
| 103 | static inline unsigned int uffs(unsigned int x) |
| 104 | { |
| 105 | unsigned int r = 1; |
| 106 | |
| 107 | if (!x) |
| 108 | return 0; |
| 109 | if (!(x & 0xffff)) { |
| 110 | x >>= 16; |
| 111 | r += 16; |
| 112 | } |
| 113 | if (!(x & 0xff)) { |
| 114 | x >>= 8; |
| 115 | r += 8; |
| 116 | } |
| 117 | if (!(x & 0xf)) { |
| 118 | x >>= 4; |
| 119 | r += 4; |
| 120 | } |
| 121 | if (!(x & 3)) { |
| 122 | x >>= 2; |
| 123 | r += 2; |
| 124 | } |
| 125 | if (!(x & 1)) { |
| 126 | x >>= 1; |
| 127 | r += 1; |
| 128 | } |
| 129 | return r; |
| 130 | } |
| 131 | |
| 132 | #define reg_read32(reg) (*(volatile u32* const)(reg)) |
| 133 | #define reg_write32(reg,val) ((*(volatile u32* const)(reg)) = (val)) |
| 134 | |
| 135 | #define reg_set_bits(reg,bs) ((*(volatile u32*)(reg)) |= (u32)(bs)) |
| 136 | #define reg_clr_bits(reg,bs) ((*(volatile u32*)(reg)) &= ~((u32)(bs))) |
| 137 | |
| 138 | #define reg_set_field(reg,field,val) \ |
| 139 | do { \ |
| 140 | volatile unsigned int tv = reg_read32(reg); \ |
| 141 | tv &= ~(field); \ |
| 142 | tv |= ((val) << (uffs((unsigned int)field) - 1)); \ |
| 143 | reg_write32(reg,tv); \ |
| 144 | } while(0) |
| 145 | |
| 146 | #define reg_get_field(reg,field,val) \ |
| 147 | do { \ |
| 148 | volatile unsigned int tv = reg_read32(reg); \ |
| 149 | val = ((tv & (field)) >> (uffs((unsigned int)field) - 1)); \ |
| 150 | } while(0) |
| 151 | |
| 152 | |
| 153 | |
| 154 | typedef enum { |
| 155 | MASTER_NFI = 0, |
| 156 | MASTER_SSUSB_XHCI = 1, |
| 157 | MASTER_PWM = 3, |
| 158 | MASTER_MSDC0 = 5, |
| 159 | MASTER_MSDC1 = 6, |
| 160 | } E_MASTER; |
| 161 | |
| 162 | |
| 163 | #define MODULE_TRANSACTION(index, is_secure) (is_secure << index) |
| 164 | #define DAPC_SET_MASTER_TRANSACTION(devapc_register, is_secure) reg_write32(devapc_register, is_secure) |
| 165 | |
| 166 | #define MODULE_DOMAIN(index, domain) (domain << (4 * (index % 8))) |
| 167 | #define DAPC_SET_MASTER_DOMAIN(devapc_register, domain) reg_write32(devapc_register, domain) |
| 168 | |
| 169 | #define MODULE_PERMISSION(index, permission) (permission << (2 * (index % 16))) |
| 170 | #define DAPC_SET_SLAVE_PERMISSION(devapc_register, permission) reg_write32(devapc_register, permission) |
| 171 | |
| 172 | typedef enum{ |
| 173 | INFRA_AO_SEJ = 10, |
| 174 | INFRA_AO_DEVICE_APC_AO_INFRA_PERI = 14, |
| 175 | INFRA_AO_DEVICE_APC_AO_MM = 28, |
| 176 | INFRASYS_DEVICE_APC = 39, |
| 177 | } E_DEVAPC0_SLAVE; |
| 178 | |
| 179 | |
| 180 | void tz_dapc_sec_init(void); |
| 181 | void tz_dapc_sec_postinit(void); |
| 182 | void tz_dapc_set_master_transaction(unsigned int master_index , E_TRANSACTION permisssion_control); |
| 183 | #endif |