1 /* SPDX-License-Identifier: (BSD-2-Clause AND BSD-3-Clause) */ 2 /* 3 * Copyright (c) 2015, Linaro Limited 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 /* 29 * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved. 30 * 31 * Redistribution and use in source and binary forms, with or without 32 * modification, are permitted provided that the following conditions are met: 33 * 34 * Redistributions of source code must retain the above copyright notice, this 35 * list of conditions and the following disclaimer. 36 * 37 * Redistributions in binary form must reproduce the above copyright notice, 38 * this list of conditions and the following disclaimer in the documentation 39 * and/or other materials provided with the distribution. 40 * 41 * Neither the name of ARM nor the names of its contributors may be used 42 * to endorse or promote products derived from this software without specific 43 * prior written permission. 44 * 45 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 46 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 48 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 49 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 50 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 51 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 52 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 53 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 55 * POSSIBILITY OF SUCH DAMAGE. 56 */ 57 58 #ifndef __DRIVERS_TZC400_H 59 #define __DRIVERS_TZC400_H 60 61 #include <stdint.h> 62 #include <types_ext.h> 63 #include <trace_levels.h> 64 #include <tee_api_types.h> 65 66 #define TZC400_REG_SIZE 0x1000 67 68 #define BUILD_CONFIG_OFF 0x000 69 #define ACTION_OFF 0x004 70 #define GATE_KEEPER_OFF 0x008 71 #define SPECULATION_CTRL_OFF 0x00c 72 #define INT_STATUS 0x010 73 #define INT_CLEAR 0x014 74 75 #define FAIL_ADDRESS_LOW_OFF 0x020 76 #define FAIL_ADDRESS_HIGH_OFF 0x024 77 #define FAIL_CONTROL_OFF 0x028 78 #define FAIL_ID_OFF 0x02c 79 #define FAIL_FILTER_OFF(idx) (0x10 * (idx)) 80 81 #define FAIL_ADDRESS_LOW(idx) (FAIL_ADDRESS_LOW_OFF + FAIL_FILTER_OFF(idx)) 82 #define FAIL_ADDRESS_HIGH(idx) (FAIL_ADDRESS_HIGH_OFF + FAIL_FILTER_OFF(idx)) 83 #define FAIL_CONTROL(idx) (FAIL_CONTROL_OFF + FAIL_FILTER_OFF(idx)) 84 #define FAIL_ID(idx) (FAIL_ID_OFF + FAIL_FILTER_OFF(idx)) 85 86 #define REGION_BASE_LOW_OFF 0x100 87 #define REGION_BASE_HIGH_OFF 0x104 88 #define REGION_TOP_LOW_OFF 0x108 89 #define REGION_TOP_HIGH_OFF 0x10c 90 #define REGION_ATTRIBUTES_OFF 0x110 91 #define REGION_ID_ACCESS_OFF 0x114 92 #define REGION_NUM_OFF(region) (0x20 * (region)) 93 94 /* ID Registers */ 95 #define PID0_OFF 0xfe0 96 #define PID1_OFF 0xfe4 97 #define PID2_OFF 0xfe8 98 #define PID3_OFF 0xfec 99 #define PID4_OFF 0xfd0 100 #define PID5_OFF 0xfd4 101 #define PID6_OFF 0xfd8 102 #define PID7_OFF 0xfdc 103 #define CID0_OFF 0xff0 104 #define CID1_OFF 0xff4 105 #define CID2_OFF 0xff8 106 #define CID3_OFF 0xffc 107 108 #define BUILD_CONFIG_NF_SHIFT 24 109 #define BUILD_CONFIG_NF_MASK 0x3 110 #define BUILD_CONFIG_AW_SHIFT 8 111 #define BUILD_CONFIG_AW_MASK 0x3f 112 #define BUILD_CONFIG_NR_SHIFT 0 113 #define BUILD_CONFIG_NR_MASK 0x1f 114 115 /* Not describing the case where regions 1 to 8 overlap */ 116 #define ACTION_RV_SHIFT 0 117 #define ACTION_RV_MASK 0x3 118 #define ACTION_RV_LOWOK 0x0 119 #define ACTION_RV_LOWERR 0x1 120 #define ACTION_RV_HIGHOK 0x2 121 #define ACTION_RV_HIGHERR 0x3 122 123 /* 124 * Number of gate keepers is implementation defined. But we know the max for 125 * this device is 4. Get implementation details from BUILD_CONFIG. 126 */ 127 #define GATE_KEEPER_OS_SHIFT 16 128 #define GATE_KEEPER_OS_MASK 0xf 129 #define GATE_KEEPER_OR_SHIFT 0 130 #define GATE_KEEPER_OR_MASK 0xf 131 #define GATE_KEEPER_FILTER_MASK 0x1 132 133 /* Speculation is enabled by default. */ 134 #define SPECULATION_CTRL_WRITE_DISABLE (1 << 1) 135 #define SPECULATION_CTRL_READ_DISABLE (1 << 0) 136 137 /* Max number of filters allowed is 4. */ 138 #define INT_STATUS_OVERLAP_SHIFT 16 139 #define INT_STATUS_OVERLAP_MASK 0xf 140 #define INT_STATUS_OVERRUN_SHIFT 8 141 #define INT_STATUS_OVERRUN_MASK 0xf 142 #define INT_STATUS_STATUS_SHIFT 0 143 #define INT_STATUS_STATUS_MASK 0xf 144 145 #define INT_CLEAR_CLEAR_SHIFT 0 146 #define INT_CLEAR_CLEAR_MASK 0xf 147 148 /* If set write access, else read access */ 149 #define FAIL_CONTROL_DIRECTION_WRITE BIT(24) 150 /* If set non-secure access, else secure access */ 151 #define FAIL_CONTROL_NONSECURE BIT(21) 152 /* If set privileged access, else unprivileged access */ 153 #define FAIL_CONTROL_PRIVILEGED BIT(20) 154 155 /* 156 * FAIL_ID_ID_MASK depends on AID_WIDTH which is platform specific. 157 * Platform should provide the value on initialisation. 158 */ 159 #define FAIL_ID_VNET_SHIFT 24 160 #define FAIL_ID_VNET_MASK 0xf 161 #define FAIL_ID_ID_SHIFT 0 162 163 /* Used along with 'enum tzc_region_attributes' below */ 164 #define REG_ATTR_SEC_SHIFT 30 165 #define REG_ATTR_F_EN_SHIFT 0 166 #define REG_ATTR_F_EN_MASK 0xf 167 #define REG_ATTR_FILTER_BIT(x) ((1 << x) << REG_ATTR_F_EN_SHIFT) 168 #define REG_ATTR_FILTER_BIT_ALL (REG_ATTR_F_EN_MASK << \ 169 REG_ATTR_F_EN_SHIFT) 170 171 #define REGION_ID_ACCESS_NSAID_WR_EN_SHIFT 16 172 #define REGION_ID_ACCESS_NSAID_RD_EN_SHIFT 0 173 #define REGION_ID_ACCESS_NSAID_ID_MASK 0xf 174 175 176 /* Macros for setting Region ID access permissions based on NSAID */ 177 #define TZC_REGION_ACCESS_RD(id) \ 178 ((1 << (id & REGION_ID_ACCESS_NSAID_ID_MASK)) << \ 179 REGION_ID_ACCESS_NSAID_RD_EN_SHIFT) 180 #define TZC_REGION_ACCESS_WR(id) \ 181 ((1 << (id & REGION_ID_ACCESS_NSAID_ID_MASK)) << \ 182 REGION_ID_ACCESS_NSAID_WR_EN_SHIFT) 183 #define TZC_REGION_ACCESS_RDWR(id) \ 184 (TZC_REGION_ACCESS_RD(id) | TZC_REGION_ACCESS_WR(id)) 185 186 /* Filters are bit mapped 0 to 3. */ 187 #define TZC400_COMPONENT_ID 0xb105f00d 188 189 /******************************************************************************* 190 * Function & variable prototypes 191 ******************************************************************************/ 192 193 /* 194 * What type of action is expected when an access violation occurs. 195 * The memory requested is zeroed. But we can also raise and event to 196 * let the system know it happened. 197 * We can raise an interrupt(INT) and/or cause an exception(ERR). 198 * TZC_ACTION_NONE - No interrupt, no Exception 199 * TZC_ACTION_ERR - No interrupt, raise exception -> sync external 200 * data abort 201 * TZC_ACTION_INT - Raise interrupt, no exception 202 * TZC_ACTION_ERR_INT - Raise interrupt, raise exception -> sync 203 * external data abort 204 */ 205 enum tzc_action { 206 TZC_ACTION_NONE = 0, 207 TZC_ACTION_ERR = 1, 208 TZC_ACTION_INT = 2, 209 TZC_ACTION_ERR_INT = (TZC_ACTION_ERR | TZC_ACTION_INT) 210 }; 211 212 /* 213 * Controls secure access to a region. If not enabled secure access is not 214 * allowed to region. 215 */ 216 enum tzc_region_attributes { 217 TZC_REGION_S_NONE = 0, 218 TZC_REGION_S_RD = 1, 219 TZC_REGION_S_WR = 2, 220 TZC_REGION_S_RDWR = (TZC_REGION_S_RD | TZC_REGION_S_WR) 221 }; 222 223 struct tzc_region_config { 224 uint32_t filters; 225 vaddr_t base; 226 vaddr_t top; 227 enum tzc_region_attributes sec_attr; 228 uint32_t ns_device_access; 229 }; 230 231 void tzc_init(vaddr_t base); 232 void tzc_configure_region(uint8_t region, const struct tzc_region_config *cfg); 233 TEE_Result tzc_get_region_config(uint8_t region, struct tzc_region_config *cfg); 234 void tzc_enable_filters(void); 235 void tzc_disable_filters(void); 236 void tzc_set_action(enum tzc_action action); 237 238 void tzc_fail_dump(void); 239 void tzc_int_clear(void); 240 241 #if TRACE_LEVEL >= TRACE_DEBUG 242 void tzc_dump_state(void); 243 #else 244 static inline void tzc_dump_state(void) 245 { 246 } 247 #endif 248 249 #endif /* __DRIVERS_TZC400_H */ 250