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) 2018 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 TZ_APC_H |
| 39 | #define TZ_APC_H |
| 40 | |
| 41 | #include "typedefs.h" |
| 42 | |
| 43 | /***************************************************************************** |
| 44 | * Register base address definition |
| 45 | *****************************************************************************/ |
| 46 | |
| 47 | #define SRAMROM_SEC_CTRL ((volatile unsigned int*)(0x10001804U)) |
| 48 | #define SRAMROM_SEC_ADDR ((volatile unsigned int*)(0x10001808U)) |
| 49 | |
| 50 | /* APDMA */ |
| 51 | #define APDMA_GLOBAL_GSEC_CTRL ((volatile unsigned int*)(0x11000014U)) |
| 52 | #define APDMA_UART_TX0_SEC_CTRL ((volatile unsigned int*)(0x11000038U)) |
| 53 | #define APDMA_UART_RX0_SEC_CTRL ((volatile unsigned int*)(0x1100003CU)) |
| 54 | #define APDMA_UART_TX1_SEC_CTRL ((volatile unsigned int*)(0x11000040U)) |
| 55 | #define APDMA_UART_RX1_SEC_CTRL ((volatile unsigned int*)(0x11000044U)) |
| 56 | #define APDMA_UART_TX2_SEC_CTRL ((volatile unsigned int*)(0x11000048U)) |
| 57 | #define APDMA_UART_RX2_SEC_CTRL ((volatile unsigned int*)(0x1100004CU)) |
| 58 | #define APDMA_UART_TX3_SEC_CTRL ((volatile unsigned int*)(0x11000050U)) |
| 59 | #define APDMA_UART_RX3_SEC_CTRL ((volatile unsigned int*)(0x11000054U)) |
| 60 | #define APDMA_UART_TX4_SEC_CTRL ((volatile unsigned int*)(0x11000058U)) |
| 61 | #define APDMA_UART_RX4_SEC_CTRL ((volatile unsigned int*)(0x1100005CU)) |
| 62 | #define APDMA_UART_TX5_SEC_CTRL ((volatile unsigned int*)(0x11000060U)) |
| 63 | #define APDMA_UART_RX5_SEC_CTRL ((volatile unsigned int*)(0x11000064U)) |
| 64 | #define APDMA_GLOBAL_GSEC_EN 0x1 |
| 65 | |
| 66 | /* CQDMA */ |
| 67 | #define CQDMA_SEC_CTRL ((volatile unsigned int*)(0x10212C58U)) |
| 68 | |
| 69 | /* SMI BDPSYS (larb8 and larb9) */ |
| 70 | #define SMI_BDPSYS_LARB8_BASE ((volatile unsigned int*)(0x1501a000U)) |
| 71 | #define SMI_BDPSYS_LARB9_BASE ((volatile unsigned int*)(0x1501a008U)) |
| 72 | #define SMI_BDPSYS_DOMAIN_MASK (0xf0000) |
| 73 | #define SMI_BDPSYS_AR_DOMAIN(dom) (((dom) & 0x3) << 16) |
| 74 | #define SMI_BDPSYS_AW_DOMAIN(dom) (((dom) & 0x3) << 18) |
| 75 | |
| 76 | /***************************************************************************** |
| 77 | * Enum |
| 78 | *****************************************************************************/ |
| 79 | typedef enum |
| 80 | { |
| 81 | TZ_APC_SEC_RW_NSEC_RW = 0, /* read and write for both secure and non-secure access */ |
| 82 | TZ_APC_SEC_RW_NSEC_DENY, /* read and write for secure access */ |
| 83 | TZ_APC_SEC_DENY_NSEC_RW, /* read and write for non-secure access */ |
| 84 | TZ_APC_SEC_DENY_NSEC_DENY /* Any access is prohibited */ |
| 85 | } tz_apc_permission; |
| 86 | |
| 87 | typedef enum |
| 88 | { |
| 89 | TZ_APC_DOMAIN_IVI = 0, /* The domain is for in-vehicle infotainment system (normally Linux OS). */ |
| 90 | TZ_APC_DOMAIN_CLUSTER = 1, /* The domain is for cluster system. */ |
| 91 | TZ_APC_DOMAIN_DSP = 2, /* The domain is for Audio DSP system. */ |
| 92 | TZ_APC_DOMAIN_MCU = 3, /* AP MCU will access the bus throgh the domain ID. The MCU used by any of the sub-system, |
| 93 | including IVI, cluster, and DSP will access the bus with this domain. |
| 94 | This domain can access almost all the slave devices in secure and non-secure mode and |
| 95 | hence we must apply the MMU and MPU to protect the device access and memory access in |
| 96 | the system. */ |
| 97 | } tz_apc_domain_partition; |
| 98 | |
| 99 | typedef enum |
| 100 | { |
| 101 | TZ_SRAMROM_SEC_RW_NSEC_RW = 0, /* read and write for both secure and non-secure access */ |
| 102 | TZ_SRAMROM_SEC_RW_NSEC_DENY = 1, /* read and write for secure access */ |
| 103 | TZ_SRAMROM_SEC_RW_NSEC_RO = 2, /* read and write for secure access and read only for non-secure access */ |
| 104 | TZ_SRAMROM_SEC_RW_NSEC_WO = 3, /* read and write for secure access and write only for non-secure access */ |
| 105 | TZ_SRAMROM_SEC_RO_NSEC_RO = 4, /* read only for both secure access and non-secure access */ |
| 106 | TZ_SRAMROM_SEC_DENY_NSEC_DENY = 7 /* Any access is prohibited */ |
| 107 | } tz_sramrom_permission; |
| 108 | |
| 109 | typedef enum |
| 110 | { |
| 111 | TZ_UART_APDMA_NSEC = 0, /* Read and write with non-secure sideband AXI signal. */ |
| 112 | TZ_UART_APDMA_SEC = 1, /* Read and write with secure sideband AXI signal. */ |
| 113 | } tz_uart_apdma_permission; |
| 114 | |
| 115 | typedef enum |
| 116 | { |
| 117 | TZ_CQDMA_NSEC = 0, /* Read and write with non-secure sideband AXI signal. */ |
| 118 | TZ_CQDMA_SEC = 1, /* Read and write with secure sideband AXI signal. */ |
| 119 | } tz_cpdma_permission; |
| 120 | |
| 121 | typedef enum |
| 122 | { |
| 123 | TZ_SRAMROM_REGION_0 = 0, /* Region 0 set by SRAMROM_SEC_ADD. Refer to TZ_SRAMROM_SET_REGION_SIZE for more info */ |
| 124 | TZ_SRAMROM_REGION_1 = 1 /* Region 1 set by SRAMROM_SEC_ADD. Refer to TZ_SRAMROM_SET_REGION_SIZE for more info */ |
| 125 | } tz_sramrom_region; |
| 126 | |
| 127 | /***************************************************************************** |
| 128 | * Functions |
| 129 | *****************************************************************************/ |
| 130 | |
| 131 | #define reg_read16(reg) __raw_readw(reg) |
| 132 | #define reg_read32(reg) __raw_readl(reg) |
| 133 | #define reg_write16(reg,val) __raw_writew(val,reg) |
| 134 | #define reg_write32(reg,val) __raw_writel(val,reg) |
| 135 | |
| 136 | static inline u32 tz_sramrom_set_bitwise_domain_permision(tz_sramrom_region region, |
| 137 | tz_apc_domain_partition domain, tz_sramrom_permission permission) |
| 138 | { |
| 139 | return (permission & 0x7) << ((domain * 3) + (region == TZ_SRAMROM_REGION_1 ? 16: 0)); |
| 140 | } |
| 141 | |
| 142 | /* Enabling this bit to protect all multimedia secure related registers, including SMI, |
| 143 | accessing in non-secure world. */ |
| 144 | #define TZ_SRAMROM_ENABLE_MULTIMEDIA_SECURE_ACCESS (u32)(0x1 << 30) |
| 145 | |
| 146 | /* Enabling this bit to protect sramrom region 1 by region 1's security setting */ |
| 147 | #define TZ_SRAMROM_ENABLE_REGION_1_PROTECTION (u32)(0x1 << 28) |
| 148 | |
| 149 | /* Set the region 0 size of the on-chip SRAM and the region 1 size will be (192KB - size_of_region_0). */ |
| 150 | #define TZ_SRAMROM_SET_REGION_0_SIZE_KB(size) (reg_write32(SRAMROM_SEC_ADDR, ((size & 0xff) << 10))) |
| 151 | |
| 152 | extern void tz_apc_common_init(); |
| 153 | extern void tz_apc_common_postinit(); |
| 154 | |
| 155 | #endif /* TZ_APC_H */ |