Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 1 | /* |
Harvey Hsieh | b9b374f | 2016-11-15 22:04:51 +0800 | [diff] [blame] | 2 | * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | #include <string.h> |
| 9 | |
| 10 | #include <arch_helpers.h> |
| 11 | #include <common/bl_common.h> |
| 12 | #include <common/debug.h> |
| 13 | #include <lib/mmio.h> |
| 14 | #include <lib/utils.h> |
| 15 | #include <lib/xlat_tables/xlat_tables_v2.h> |
| 16 | |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 17 | #include <mce.h> |
| 18 | #include <memctrl.h> |
| 19 | #include <memctrl_v2.h> |
Varun Wadekar | 87e44ff | 2016-03-03 13:22:39 -0800 | [diff] [blame] | 20 | #include <smmu.h> |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 21 | #include <tegra_def.h> |
Varun Wadekar | e81177d | 2016-07-18 17:43:41 -0700 | [diff] [blame] | 22 | #include <tegra_platform.h> |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 23 | |
| 24 | /* Video Memory base and size (live values) */ |
| 25 | static uint64_t video_mem_base; |
Varun Wadekar | 7058aee | 2016-04-25 09:01:46 -0700 | [diff] [blame] | 26 | static uint64_t video_mem_size_mb; |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 27 | |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 28 | /* |
Varun Wadekar | f3cd509 | 2017-10-30 14:35:17 -0700 | [diff] [blame] | 29 | * The following platform setup functions are weakly defined. They |
| 30 | * provide typical implementations that will be overridden by a SoC. |
| 31 | */ |
| 32 | #pragma weak plat_memctrl_tzdram_setup |
Steven Kao | a457f2e | 2017-11-14 18:52:05 +0800 | [diff] [blame] | 33 | |
Varun Wadekar | f3cd509 | 2017-10-30 14:35:17 -0700 | [diff] [blame] | 34 | void plat_memctrl_tzdram_setup(uint64_t phys_base, uint64_t size_in_bytes) |
| 35 | { |
| 36 | ; /* do nothing */ |
| 37 | } |
| 38 | |
| 39 | /* |
Varun Wadekar | 87e44ff | 2016-03-03 13:22:39 -0800 | [diff] [blame] | 40 | * Init Memory controller during boot. |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 41 | */ |
| 42 | void tegra_memctrl_setup(void) |
| 43 | { |
| 44 | uint32_t val; |
Pritesh Raithatha | 9eb5db5 | 2017-01-02 19:42:31 +0530 | [diff] [blame] | 45 | const uint32_t *mc_streamid_override_regs; |
| 46 | uint32_t num_streamid_override_regs; |
| 47 | const mc_streamid_security_cfg_t *mc_streamid_sec_cfgs; |
| 48 | uint32_t num_streamid_sec_cfgs; |
Anthony Zhou | 0844b97 | 2017-06-28 16:35:54 +0800 | [diff] [blame] | 49 | const tegra_mc_settings_t *plat_mc_settings = tegra_get_mc_settings(); |
Varun Wadekar | ad45ef7 | 2017-04-03 13:44:57 -0700 | [diff] [blame] | 50 | uint32_t i; |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 51 | |
| 52 | INFO("Tegra Memory Controller (v2)\n"); |
| 53 | |
| 54 | /* Program the SMMU pagesize */ |
Varun Wadekar | 87e44ff | 2016-03-03 13:22:39 -0800 | [diff] [blame] | 55 | tegra_smmu_init(); |
Varun Wadekar | cba0529 | 2017-11-29 17:14:24 -0800 | [diff] [blame] | 56 | |
Pritesh Raithatha | 9eb5db5 | 2017-01-02 19:42:31 +0530 | [diff] [blame] | 57 | /* Get the settings from the platform */ |
Anthony Zhou | 4408e88 | 2017-07-07 14:29:51 +0800 | [diff] [blame] | 58 | assert(plat_mc_settings != NULL); |
Pritesh Raithatha | 9eb5db5 | 2017-01-02 19:42:31 +0530 | [diff] [blame] | 59 | mc_streamid_override_regs = plat_mc_settings->streamid_override_cfg; |
| 60 | num_streamid_override_regs = plat_mc_settings->num_streamid_override_cfgs; |
| 61 | mc_streamid_sec_cfgs = plat_mc_settings->streamid_security_cfg; |
| 62 | num_streamid_sec_cfgs = plat_mc_settings->num_streamid_security_cfgs; |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 63 | |
| 64 | /* Program all the Stream ID overrides */ |
Pritesh Raithatha | 9eb5db5 | 2017-01-02 19:42:31 +0530 | [diff] [blame] | 65 | for (i = 0; i < num_streamid_override_regs; i++) |
| 66 | tegra_mc_streamid_write_32(mc_streamid_override_regs[i], |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 67 | MC_STREAM_ID_MAX); |
| 68 | |
| 69 | /* Program the security config settings for all Stream IDs */ |
Pritesh Raithatha | 9eb5db5 | 2017-01-02 19:42:31 +0530 | [diff] [blame] | 70 | for (i = 0; i < num_streamid_sec_cfgs; i++) { |
| 71 | val = mc_streamid_sec_cfgs[i].override_enable << 16 | |
| 72 | mc_streamid_sec_cfgs[i].override_client_inputs << 8 | |
| 73 | mc_streamid_sec_cfgs[i].override_client_ns_flag << 0; |
| 74 | tegra_mc_streamid_write_32(mc_streamid_sec_cfgs[i].offset, val); |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* |
| 78 | * All requests at boot time, and certain requests during |
| 79 | * normal run time, are physically addressed and must bypass |
| 80 | * the SMMU. The client hub logic implements a hardware bypass |
| 81 | * path around the Translation Buffer Units (TBU). During |
| 82 | * boot-time, the SMMU_BYPASS_CTRL register (which defaults to |
| 83 | * TBU_BYPASS mode) will be used to steer all requests around |
| 84 | * the uninitialized TBUs. During normal operation, this register |
| 85 | * is locked into TBU_BYPASS_SID config, which routes requests |
| 86 | * with special StreamID 0x7f on the bypass path and all others |
| 87 | * through the selected TBU. This is done to disable SMMU Bypass |
| 88 | * mode, as it could be used to circumvent SMMU security checks. |
| 89 | */ |
| 90 | tegra_mc_write_32(MC_SMMU_BYPASS_CONFIG, |
Pritesh Raithatha | 9eb5db5 | 2017-01-02 19:42:31 +0530 | [diff] [blame] | 91 | MC_SMMU_BYPASS_CONFIG_SETTINGS); |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 92 | |
Varun Wadekar | c9ac3e4 | 2016-02-17 15:07:49 -0800 | [diff] [blame] | 93 | /* |
Varun Wadekar | a0f2697 | 2016-03-11 17:18:51 -0800 | [diff] [blame] | 94 | * Re-configure MSS to allow ROC to deal with ordering of the |
| 95 | * Memory Controller traffic. This is needed as the Memory Controller |
| 96 | * boots with MSS having all control, but ROC provides a performance |
| 97 | * boost as compared to MSS. |
| 98 | */ |
Puneet Saxena | cf8c0e2 | 2017-08-04 17:19:55 +0530 | [diff] [blame] | 99 | if (plat_mc_settings->reconfig_mss_clients != NULL) { |
| 100 | plat_mc_settings->reconfig_mss_clients(); |
| 101 | } |
Varun Wadekar | a0f2697 | 2016-03-11 17:18:51 -0800 | [diff] [blame] | 102 | |
Varun Wadekar | ad45ef7 | 2017-04-03 13:44:57 -0700 | [diff] [blame] | 103 | /* Program overrides for MC transactions */ |
Puneet Saxena | cf8c0e2 | 2017-08-04 17:19:55 +0530 | [diff] [blame] | 104 | if (plat_mc_settings->set_txn_overrides != NULL) { |
| 105 | plat_mc_settings->set_txn_overrides(); |
| 106 | } |
Varun Wadekar | 87e44ff | 2016-03-03 13:22:39 -0800 | [diff] [blame] | 107 | } |
Varun Wadekar | c9ac3e4 | 2016-02-17 15:07:49 -0800 | [diff] [blame] | 108 | |
Varun Wadekar | 87e44ff | 2016-03-03 13:22:39 -0800 | [diff] [blame] | 109 | /* |
| 110 | * Restore Memory Controller settings after "System Suspend" |
| 111 | */ |
| 112 | void tegra_memctrl_restore_settings(void) |
| 113 | { |
Puneet Saxena | cf8c0e2 | 2017-08-04 17:19:55 +0530 | [diff] [blame] | 114 | const tegra_mc_settings_t *plat_mc_settings = tegra_get_mc_settings(); |
| 115 | |
| 116 | assert(plat_mc_settings != NULL); |
| 117 | |
Varun Wadekar | a0f2697 | 2016-03-11 17:18:51 -0800 | [diff] [blame] | 118 | /* |
| 119 | * Re-configure MSS to allow ROC to deal with ordering of the |
| 120 | * Memory Controller traffic. This is needed as the Memory Controller |
| 121 | * resets during System Suspend with MSS having all control, but ROC |
| 122 | * provides a performance boost as compared to MSS. |
| 123 | */ |
Puneet Saxena | cf8c0e2 | 2017-08-04 17:19:55 +0530 | [diff] [blame] | 124 | if (plat_mc_settings->reconfig_mss_clients != NULL) { |
| 125 | plat_mc_settings->reconfig_mss_clients(); |
| 126 | } |
Varun Wadekar | a0f2697 | 2016-03-11 17:18:51 -0800 | [diff] [blame] | 127 | |
Varun Wadekar | ad45ef7 | 2017-04-03 13:44:57 -0700 | [diff] [blame] | 128 | /* Program overrides for MC transactions */ |
Puneet Saxena | cf8c0e2 | 2017-08-04 17:19:55 +0530 | [diff] [blame] | 129 | if (plat_mc_settings->set_txn_overrides != NULL) { |
| 130 | plat_mc_settings->set_txn_overrides(); |
| 131 | } |
Varun Wadekar | ad45ef7 | 2017-04-03 13:44:57 -0700 | [diff] [blame] | 132 | |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 133 | /* video memory carveout region */ |
Anthony Zhou | 0e07e45 | 2017-07-26 17:16:54 +0800 | [diff] [blame] | 134 | if (video_mem_base != 0ULL) { |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 135 | tegra_mc_write_32(MC_VIDEO_PROTECT_BASE_LO, |
| 136 | (uint32_t)video_mem_base); |
| 137 | tegra_mc_write_32(MC_VIDEO_PROTECT_BASE_HI, |
| 138 | (uint32_t)(video_mem_base >> 32)); |
Varun Wadekar | 7058aee | 2016-04-25 09:01:46 -0700 | [diff] [blame] | 139 | tegra_mc_write_32(MC_VIDEO_PROTECT_SIZE_MB, video_mem_size_mb); |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 140 | |
| 141 | /* |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 142 | * MCE propagates the VideoMem configuration values across the |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 143 | * CCPLEX. |
| 144 | */ |
| 145 | mce_update_gsc_videomem(); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /* |
| 150 | * Secure the BL31 DRAM aperture. |
| 151 | * |
| 152 | * phys_base = physical base of TZDRAM aperture |
| 153 | * size_in_bytes = size of aperture in bytes |
| 154 | */ |
| 155 | void tegra_memctrl_tzdram_setup(uint64_t phys_base, uint32_t size_in_bytes) |
| 156 | { |
| 157 | /* |
Varun Wadekar | f3cd509 | 2017-10-30 14:35:17 -0700 | [diff] [blame] | 158 | * Perform platform specific steps. |
Harvey Hsieh | c95802d | 2016-07-29 20:10:59 +0800 | [diff] [blame] | 159 | */ |
Varun Wadekar | f3cd509 | 2017-10-30 14:35:17 -0700 | [diff] [blame] | 160 | plat_memctrl_tzdram_setup(phys_base, size_in_bytes); |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /* |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 164 | * Secure the BL31 TZRAM aperture. |
| 165 | * |
| 166 | * phys_base = physical base of TZRAM aperture |
| 167 | * size_in_bytes = size of aperture in bytes |
| 168 | */ |
| 169 | void tegra_memctrl_tzram_setup(uint64_t phys_base, uint32_t size_in_bytes) |
| 170 | { |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 171 | uint32_t index; |
| 172 | uint32_t total_128kb_blocks = size_in_bytes >> 17; |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 173 | uint32_t residual_4kb_blocks = (size_in_bytes & (uint32_t)0x1FFFF) >> 12; |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 174 | uint32_t val; |
| 175 | |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 176 | INFO("Configuring TrustZone SRAM Memory Carveout\n"); |
| 177 | |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 178 | /* |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 179 | * Reset the access configuration registers to restrict access |
| 180 | * to the TZRAM aperture |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 181 | */ |
Steven Kao | b688d38 | 2017-09-06 13:32:21 +0800 | [diff] [blame] | 182 | for (index = MC_TZRAM_CLIENT_ACCESS0_CFG0; |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 183 | index < ((uint32_t)MC_TZRAM_CARVEOUT_CFG + (uint32_t)MC_GSC_CONFIG_REGS_SIZE); |
| 184 | index += 4U) { |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 185 | tegra_mc_write_32(index, 0); |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 186 | } |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 187 | |
| 188 | /* |
Steven Kao | b688d38 | 2017-09-06 13:32:21 +0800 | [diff] [blame] | 189 | * Enable CPU access configuration registers to access the TZRAM aperture |
| 190 | */ |
| 191 | if (!tegra_chipid_is_t186()) { |
| 192 | val = tegra_mc_read_32(MC_TZRAM_CLIENT_ACCESS1_CFG0); |
| 193 | val |= TZRAM_ALLOW_MPCORER | TZRAM_ALLOW_MPCOREW; |
| 194 | tegra_mc_write_32(MC_TZRAM_CLIENT_ACCESS1_CFG0, val); |
| 195 | } |
| 196 | |
| 197 | /* |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 198 | * Set the TZRAM base. TZRAM base must be 4k aligned, at least. |
| 199 | */ |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 200 | assert((phys_base & (uint64_t)0xFFF) == 0U); |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 201 | tegra_mc_write_32(MC_TZRAM_BASE_LO, (uint32_t)phys_base); |
| 202 | tegra_mc_write_32(MC_TZRAM_BASE_HI, |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 203 | (uint32_t)(phys_base >> 32) & MC_GSC_BASE_HI_MASK); |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 204 | |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 205 | /* |
| 206 | * Set the TZRAM size |
| 207 | * |
| 208 | * total size = (number of 128KB blocks) + (number of remaining 4KB |
| 209 | * blocks) |
| 210 | * |
| 211 | */ |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 212 | val = (residual_4kb_blocks << MC_GSC_SIZE_RANGE_4KB_SHIFT) | |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 213 | total_128kb_blocks; |
| 214 | tegra_mc_write_32(MC_TZRAM_SIZE, val); |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 215 | |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 216 | /* |
| 217 | * Lock the configuration settings by disabling TZ-only lock |
| 218 | * and locking the configuration against any future changes |
| 219 | * at all. |
| 220 | */ |
| 221 | val = tegra_mc_read_32(MC_TZRAM_CARVEOUT_CFG); |
Anthony Zhou | 0844b97 | 2017-06-28 16:35:54 +0800 | [diff] [blame] | 222 | val &= (uint32_t)~MC_GSC_ENABLE_TZ_LOCK_BIT; |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 223 | val |= MC_GSC_LOCK_CFG_SETTINGS_BIT; |
Steven Kao | b688d38 | 2017-09-06 13:32:21 +0800 | [diff] [blame] | 224 | if (!tegra_chipid_is_t186()) { |
| 225 | val |= MC_GSC_ENABLE_CPU_SECURE_BIT; |
| 226 | } |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 227 | tegra_mc_write_32(MC_TZRAM_CARVEOUT_CFG, val); |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 228 | |
| 229 | /* |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 230 | * MCE propagates the security configuration values across the |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 231 | * CCPLEX. |
| 232 | */ |
| 233 | mce_update_gsc_tzram(); |
| 234 | } |
| 235 | |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 236 | static void tegra_lock_videomem_nonoverlap(uint64_t phys_base, |
| 237 | uint64_t size_in_bytes) |
| 238 | { |
| 239 | uint32_t index; |
| 240 | uint64_t total_128kb_blocks = size_in_bytes >> 17; |
| 241 | uint64_t residual_4kb_blocks = (size_in_bytes & (uint32_t)0x1FFFF) >> 12; |
| 242 | uint64_t val; |
| 243 | |
| 244 | /* |
| 245 | * Reset the access configuration registers to restrict access to |
| 246 | * old Videomem aperture |
| 247 | */ |
| 248 | for (index = MC_VIDEO_PROTECT_CLEAR_ACCESS_CFG0; |
| 249 | index < ((uint32_t)MC_VIDEO_PROTECT_CLEAR_ACCESS_CFG0 + (uint32_t)MC_GSC_CONFIG_REGS_SIZE); |
| 250 | index += 4U) { |
| 251 | tegra_mc_write_32(index, 0); |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * Set the base. It must be 4k aligned, at least. |
| 256 | */ |
| 257 | assert((phys_base & (uint64_t)0xFFF) == 0U); |
| 258 | tegra_mc_write_32(MC_VIDEO_PROTECT_CLEAR_BASE_LO, (uint32_t)phys_base); |
| 259 | tegra_mc_write_32(MC_VIDEO_PROTECT_CLEAR_BASE_HI, |
| 260 | (uint32_t)(phys_base >> 32) & (uint32_t)MC_GSC_BASE_HI_MASK); |
| 261 | |
| 262 | /* |
| 263 | * Set the aperture size |
| 264 | * |
| 265 | * total size = (number of 128KB blocks) + (number of remaining 4KB |
| 266 | * blocks) |
| 267 | * |
| 268 | */ |
| 269 | val = (uint32_t)((residual_4kb_blocks << MC_GSC_SIZE_RANGE_4KB_SHIFT) | |
| 270 | total_128kb_blocks); |
| 271 | tegra_mc_write_32(MC_VIDEO_PROTECT_CLEAR_SIZE, (uint32_t)val); |
| 272 | |
| 273 | /* |
| 274 | * Lock the configuration settings by enabling TZ-only lock and |
| 275 | * locking the configuration against any future changes from NS |
| 276 | * world. |
| 277 | */ |
| 278 | tegra_mc_write_32(MC_VIDEO_PROTECT_CLEAR_CFG, |
| 279 | (uint32_t)MC_GSC_ENABLE_TZ_LOCK_BIT); |
| 280 | |
| 281 | /* |
| 282 | * MCE propagates the GSC configuration values across the |
| 283 | * CCPLEX. |
| 284 | */ |
| 285 | } |
| 286 | |
| 287 | static void tegra_unlock_videomem_nonoverlap(void) |
| 288 | { |
| 289 | /* Clear the base */ |
| 290 | tegra_mc_write_32(MC_VIDEO_PROTECT_CLEAR_BASE_LO, 0); |
| 291 | tegra_mc_write_32(MC_VIDEO_PROTECT_CLEAR_BASE_HI, 0); |
| 292 | |
| 293 | /* Clear the size */ |
| 294 | tegra_mc_write_32(MC_VIDEO_PROTECT_CLEAR_SIZE, 0); |
| 295 | } |
| 296 | |
| 297 | static void tegra_clear_videomem(uintptr_t non_overlap_area_start, |
| 298 | unsigned long long non_overlap_area_size) |
| 299 | { |
Varun Wadekar | 117a2e0 | 2017-08-03 11:40:34 -0700 | [diff] [blame] | 300 | int ret; |
| 301 | |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 302 | /* |
| 303 | * Map the NS memory first, clean it and then unmap it. |
| 304 | */ |
Varun Wadekar | 117a2e0 | 2017-08-03 11:40:34 -0700 | [diff] [blame] | 305 | ret = mmap_add_dynamic_region(non_overlap_area_start, /* PA */ |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 306 | non_overlap_area_start, /* VA */ |
| 307 | non_overlap_area_size, /* size */ |
| 308 | MT_NS | MT_RW | MT_EXECUTE_NEVER); /* attrs */ |
Varun Wadekar | 117a2e0 | 2017-08-03 11:40:34 -0700 | [diff] [blame] | 309 | assert(ret == 0); |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 310 | |
| 311 | zero_normalmem((void *)non_overlap_area_start, non_overlap_area_size); |
| 312 | flush_dcache_range(non_overlap_area_start, non_overlap_area_size); |
| 313 | |
Anthony Zhou | 0844b97 | 2017-06-28 16:35:54 +0800 | [diff] [blame] | 314 | (void)mmap_remove_dynamic_region(non_overlap_area_start, |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 315 | non_overlap_area_size); |
| 316 | } |
| 317 | |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 318 | /* |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 319 | * Program the Video Memory carveout region |
| 320 | * |
| 321 | * phys_base = physical base of aperture |
| 322 | * size_in_bytes = size of aperture in bytes |
| 323 | */ |
| 324 | void tegra_memctrl_videomem_setup(uint64_t phys_base, uint32_t size_in_bytes) |
| 325 | { |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 326 | uintptr_t vmem_end_old = video_mem_base + (video_mem_size_mb << 20); |
| 327 | uintptr_t vmem_end_new = phys_base + size_in_bytes; |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 328 | unsigned long long non_overlap_area_size; |
Varun Wadekar | e60f1bf | 2016-02-17 10:10:50 -0800 | [diff] [blame] | 329 | |
| 330 | /* |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 331 | * Setup the Memory controller to restrict CPU accesses to the Video |
| 332 | * Memory region |
| 333 | */ |
| 334 | INFO("Configuring Video Memory Carveout\n"); |
| 335 | |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 336 | /* |
| 337 | * Configure Memory Controller directly for the first time. |
| 338 | */ |
| 339 | if (video_mem_base == 0U) |
| 340 | goto done; |
| 341 | |
| 342 | /* |
| 343 | * Lock the non overlapping memory being cleared so that other masters |
| 344 | * do not accidently write to it. The memory would be unlocked once |
| 345 | * the non overlapping region is cleared and the new memory |
| 346 | * settings take effect. |
| 347 | */ |
| 348 | tegra_lock_videomem_nonoverlap(video_mem_base, |
| 349 | video_mem_size_mb << 20); |
| 350 | |
| 351 | /* |
| 352 | * Clear the old regions now being exposed. The following cases |
| 353 | * can occur - |
| 354 | * |
| 355 | * 1. clear whole old region (no overlap with new region) |
| 356 | * 2. clear old sub-region below new base |
| 357 | * 3. clear old sub-region above new end |
| 358 | */ |
| 359 | INFO("Cleaning previous Video Memory Carveout\n"); |
| 360 | |
Anthony Zhou | 0844b97 | 2017-06-28 16:35:54 +0800 | [diff] [blame] | 361 | if ((phys_base > vmem_end_old) || (video_mem_base > vmem_end_new)) { |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 362 | tegra_clear_videomem(video_mem_base, |
Anthony Zhou | 0844b97 | 2017-06-28 16:35:54 +0800 | [diff] [blame] | 363 | (uint32_t)video_mem_size_mb << 20U); |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 364 | } else { |
| 365 | if (video_mem_base < phys_base) { |
| 366 | non_overlap_area_size = phys_base - video_mem_base; |
Anthony Zhou | 0844b97 | 2017-06-28 16:35:54 +0800 | [diff] [blame] | 367 | tegra_clear_videomem(video_mem_base, |
| 368 | (uint32_t)non_overlap_area_size); |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 369 | } |
| 370 | if (vmem_end_old > vmem_end_new) { |
| 371 | non_overlap_area_size = vmem_end_old - vmem_end_new; |
Anthony Zhou | 0844b97 | 2017-06-28 16:35:54 +0800 | [diff] [blame] | 372 | tegra_clear_videomem(vmem_end_new, |
| 373 | (uint32_t)non_overlap_area_size); |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
| 377 | done: |
| 378 | /* program the Videomem aperture */ |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 379 | tegra_mc_write_32(MC_VIDEO_PROTECT_BASE_LO, (uint32_t)phys_base); |
| 380 | tegra_mc_write_32(MC_VIDEO_PROTECT_BASE_HI, |
| 381 | (uint32_t)(phys_base >> 32)); |
Varun Wadekar | 7058aee | 2016-04-25 09:01:46 -0700 | [diff] [blame] | 382 | tegra_mc_write_32(MC_VIDEO_PROTECT_SIZE_MB, size_in_bytes >> 20); |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 383 | |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 384 | /* unlock the previous locked nonoverlapping aperture */ |
| 385 | tegra_unlock_videomem_nonoverlap(); |
| 386 | |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 387 | /* store new values */ |
| 388 | video_mem_base = phys_base; |
Varun Wadekar | 7058aee | 2016-04-25 09:01:46 -0700 | [diff] [blame] | 389 | video_mem_size_mb = size_in_bytes >> 20; |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 390 | |
| 391 | /* |
Varun Wadekar | 153982c | 2016-12-21 14:50:18 -0800 | [diff] [blame] | 392 | * MCE propagates the VideoMem configuration values across the |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 393 | * CCPLEX. |
| 394 | */ |
| 395 | mce_update_gsc_videomem(); |
| 396 | } |
Varun Wadekar | c92050b | 2017-03-29 14:57:29 -0700 | [diff] [blame] | 397 | |
| 398 | /* |
| 399 | * This feature exists only for v1 of the Tegra Memory Controller. |
| 400 | */ |
| 401 | void tegra_memctrl_disable_ahb_redirection(void) |
| 402 | { |
| 403 | ; /* do nothing */ |
| 404 | } |
Harvey Hsieh | 359be95 | 2017-08-21 15:01:53 +0800 | [diff] [blame] | 405 | |
| 406 | void tegra_memctrl_clear_pending_interrupts(void) |
| 407 | { |
| 408 | ; /* do nothing */ |
| 409 | } |