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