Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 1 | /* |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 2 | * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <arch_helpers.h> |
| 32 | #include <assert.h> |
| 33 | #include <debug.h> |
| 34 | #include <mce.h> |
| 35 | #include <memctrl.h> |
| 36 | #include <memctrl_v2.h> |
| 37 | #include <mmio.h> |
Varun Wadekar | 87e44ff | 2016-03-03 13:22:39 -0800 | [diff] [blame] | 38 | #include <smmu.h> |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 39 | #include <string.h> |
| 40 | #include <tegra_def.h> |
Varun Wadekar | e81177d | 2016-07-18 17:43:41 -0700 | [diff] [blame] | 41 | #include <tegra_platform.h> |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 42 | #include <xlat_tables.h> |
| 43 | |
Varun Wadekar | e60f1bf | 2016-02-17 10:10:50 -0800 | [diff] [blame] | 44 | #define TEGRA_GPU_RESET_REG_OFFSET 0x30 |
| 45 | #define GPU_RESET_BIT (1 << 0) |
| 46 | |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 47 | /* Video Memory base and size (live values) */ |
| 48 | static uint64_t video_mem_base; |
Varun Wadekar | 7058aee | 2016-04-25 09:01:46 -0700 | [diff] [blame] | 49 | static uint64_t video_mem_size_mb; |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 50 | |
| 51 | /* array to hold stream_id override config register offsets */ |
| 52 | const static uint32_t streamid_overrides[] = { |
| 53 | MC_STREAMID_OVERRIDE_CFG_PTCR, |
| 54 | MC_STREAMID_OVERRIDE_CFG_AFIR, |
| 55 | MC_STREAMID_OVERRIDE_CFG_HDAR, |
| 56 | MC_STREAMID_OVERRIDE_CFG_HOST1XDMAR, |
| 57 | MC_STREAMID_OVERRIDE_CFG_NVENCSRD, |
| 58 | MC_STREAMID_OVERRIDE_CFG_SATAR, |
| 59 | MC_STREAMID_OVERRIDE_CFG_MPCORER, |
| 60 | MC_STREAMID_OVERRIDE_CFG_NVENCSWR, |
| 61 | MC_STREAMID_OVERRIDE_CFG_AFIW, |
| 62 | MC_STREAMID_OVERRIDE_CFG_SATAW, |
| 63 | MC_STREAMID_OVERRIDE_CFG_MPCOREW, |
| 64 | MC_STREAMID_OVERRIDE_CFG_SATAW, |
| 65 | MC_STREAMID_OVERRIDE_CFG_HDAW, |
| 66 | MC_STREAMID_OVERRIDE_CFG_ISPRA, |
| 67 | MC_STREAMID_OVERRIDE_CFG_ISPWA, |
| 68 | MC_STREAMID_OVERRIDE_CFG_ISPWB, |
| 69 | MC_STREAMID_OVERRIDE_CFG_XUSB_HOSTR, |
| 70 | MC_STREAMID_OVERRIDE_CFG_XUSB_HOSTW, |
| 71 | MC_STREAMID_OVERRIDE_CFG_XUSB_DEVR, |
| 72 | MC_STREAMID_OVERRIDE_CFG_XUSB_DEVW, |
| 73 | MC_STREAMID_OVERRIDE_CFG_TSECSRD, |
| 74 | MC_STREAMID_OVERRIDE_CFG_TSECSWR, |
| 75 | MC_STREAMID_OVERRIDE_CFG_GPUSRD, |
| 76 | MC_STREAMID_OVERRIDE_CFG_GPUSWR, |
| 77 | MC_STREAMID_OVERRIDE_CFG_SDMMCRA, |
| 78 | MC_STREAMID_OVERRIDE_CFG_SDMMCRAA, |
| 79 | MC_STREAMID_OVERRIDE_CFG_SDMMCR, |
| 80 | MC_STREAMID_OVERRIDE_CFG_SDMMCRAB, |
| 81 | MC_STREAMID_OVERRIDE_CFG_SDMMCWA, |
| 82 | MC_STREAMID_OVERRIDE_CFG_SDMMCWAA, |
| 83 | MC_STREAMID_OVERRIDE_CFG_SDMMCW, |
| 84 | MC_STREAMID_OVERRIDE_CFG_SDMMCWAB, |
| 85 | MC_STREAMID_OVERRIDE_CFG_VICSRD, |
| 86 | MC_STREAMID_OVERRIDE_CFG_VICSWR, |
| 87 | MC_STREAMID_OVERRIDE_CFG_VIW, |
| 88 | MC_STREAMID_OVERRIDE_CFG_NVDECSRD, |
| 89 | MC_STREAMID_OVERRIDE_CFG_NVDECSWR, |
| 90 | MC_STREAMID_OVERRIDE_CFG_APER, |
| 91 | MC_STREAMID_OVERRIDE_CFG_APEW, |
| 92 | MC_STREAMID_OVERRIDE_CFG_NVJPGSRD, |
| 93 | MC_STREAMID_OVERRIDE_CFG_NVJPGSWR, |
| 94 | MC_STREAMID_OVERRIDE_CFG_SESRD, |
| 95 | MC_STREAMID_OVERRIDE_CFG_SESWR, |
| 96 | MC_STREAMID_OVERRIDE_CFG_ETRR, |
| 97 | MC_STREAMID_OVERRIDE_CFG_ETRW, |
| 98 | MC_STREAMID_OVERRIDE_CFG_TSECSRDB, |
| 99 | MC_STREAMID_OVERRIDE_CFG_TSECSWRB, |
| 100 | MC_STREAMID_OVERRIDE_CFG_GPUSRD2, |
| 101 | MC_STREAMID_OVERRIDE_CFG_GPUSWR2, |
| 102 | MC_STREAMID_OVERRIDE_CFG_AXISR, |
| 103 | MC_STREAMID_OVERRIDE_CFG_AXISW, |
| 104 | MC_STREAMID_OVERRIDE_CFG_EQOSR, |
| 105 | MC_STREAMID_OVERRIDE_CFG_EQOSW, |
| 106 | MC_STREAMID_OVERRIDE_CFG_UFSHCR, |
| 107 | MC_STREAMID_OVERRIDE_CFG_UFSHCW, |
| 108 | MC_STREAMID_OVERRIDE_CFG_NVDISPLAYR, |
| 109 | MC_STREAMID_OVERRIDE_CFG_BPMPR, |
| 110 | MC_STREAMID_OVERRIDE_CFG_BPMPW, |
| 111 | MC_STREAMID_OVERRIDE_CFG_BPMPDMAR, |
| 112 | MC_STREAMID_OVERRIDE_CFG_BPMPDMAW, |
| 113 | MC_STREAMID_OVERRIDE_CFG_AONR, |
| 114 | MC_STREAMID_OVERRIDE_CFG_AONW, |
| 115 | MC_STREAMID_OVERRIDE_CFG_AONDMAR, |
| 116 | MC_STREAMID_OVERRIDE_CFG_AONDMAW, |
| 117 | MC_STREAMID_OVERRIDE_CFG_SCER, |
| 118 | MC_STREAMID_OVERRIDE_CFG_SCEW, |
| 119 | MC_STREAMID_OVERRIDE_CFG_SCEDMAR, |
| 120 | MC_STREAMID_OVERRIDE_CFG_SCEDMAW, |
| 121 | MC_STREAMID_OVERRIDE_CFG_APEDMAR, |
| 122 | MC_STREAMID_OVERRIDE_CFG_APEDMAW, |
| 123 | MC_STREAMID_OVERRIDE_CFG_NVDISPLAYR1, |
| 124 | MC_STREAMID_OVERRIDE_CFG_VICSRD1, |
| 125 | MC_STREAMID_OVERRIDE_CFG_NVDECSRD1 |
| 126 | }; |
| 127 | |
| 128 | /* array to hold the security configs for stream IDs */ |
| 129 | const static mc_streamid_security_cfg_t sec_cfgs[] = { |
Varun Wadekar | de729d6 | 2016-02-17 10:01:28 -0800 | [diff] [blame] | 130 | mc_make_sec_cfg(SCEW, NON_SECURE, NO_OVERRIDE, ENABLE), |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 131 | mc_make_sec_cfg(AFIR, NON_SECURE, OVERRIDE, ENABLE), |
| 132 | mc_make_sec_cfg(NVDISPLAYR1, NON_SECURE, OVERRIDE, ENABLE), |
| 133 | mc_make_sec_cfg(XUSB_DEVR, NON_SECURE, OVERRIDE, ENABLE), |
| 134 | mc_make_sec_cfg(VICSRD1, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 135 | mc_make_sec_cfg(NVENCSWR, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 136 | mc_make_sec_cfg(TSECSRDB, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 137 | mc_make_sec_cfg(AXISW, SECURE, NO_OVERRIDE, DISABLE), |
| 138 | mc_make_sec_cfg(SDMMCWAB, NON_SECURE, OVERRIDE, ENABLE), |
| 139 | mc_make_sec_cfg(AONDMAW, NON_SECURE, OVERRIDE, ENABLE), |
| 140 | mc_make_sec_cfg(GPUSWR2, SECURE, NO_OVERRIDE, DISABLE), |
| 141 | mc_make_sec_cfg(SATAW, NON_SECURE, OVERRIDE, ENABLE), |
| 142 | mc_make_sec_cfg(UFSHCW, NON_SECURE, OVERRIDE, ENABLE), |
| 143 | mc_make_sec_cfg(AFIW, NON_SECURE, OVERRIDE, ENABLE), |
| 144 | mc_make_sec_cfg(SDMMCR, NON_SECURE, OVERRIDE, ENABLE), |
Varun Wadekar | de729d6 | 2016-02-17 10:01:28 -0800 | [diff] [blame] | 145 | mc_make_sec_cfg(SCEDMAW, NON_SECURE, NO_OVERRIDE, ENABLE), |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 146 | mc_make_sec_cfg(UFSHCR, NON_SECURE, OVERRIDE, ENABLE), |
| 147 | mc_make_sec_cfg(SDMMCWAA, NON_SECURE, OVERRIDE, ENABLE), |
Varun Wadekar | 0012d05 | 2016-04-19 14:22:13 -0700 | [diff] [blame] | 148 | mc_make_sec_cfg(SESWR, NON_SECURE, NO_OVERRIDE, ENABLE), |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 149 | mc_make_sec_cfg(MPCORER, NON_SECURE, OVERRIDE, ENABLE), |
| 150 | mc_make_sec_cfg(PTCR, NON_SECURE, OVERRIDE, ENABLE), |
| 151 | mc_make_sec_cfg(BPMPW, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 152 | mc_make_sec_cfg(ETRW, NON_SECURE, OVERRIDE, ENABLE), |
| 153 | mc_make_sec_cfg(GPUSRD, SECURE, NO_OVERRIDE, DISABLE), |
| 154 | mc_make_sec_cfg(VICSWR, NON_SECURE, NO_OVERRIDE, ENABLE), |
Varun Wadekar | de729d6 | 2016-02-17 10:01:28 -0800 | [diff] [blame] | 155 | mc_make_sec_cfg(SCEDMAR, NON_SECURE, NO_OVERRIDE, ENABLE), |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 156 | mc_make_sec_cfg(HDAW, NON_SECURE, OVERRIDE, ENABLE), |
| 157 | mc_make_sec_cfg(ISPWA, NON_SECURE, OVERRIDE, ENABLE), |
| 158 | mc_make_sec_cfg(EQOSW, NON_SECURE, OVERRIDE, ENABLE), |
| 159 | mc_make_sec_cfg(XUSB_HOSTW, NON_SECURE, OVERRIDE, ENABLE), |
| 160 | mc_make_sec_cfg(TSECSWR, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 161 | mc_make_sec_cfg(SDMMCRAA, NON_SECURE, OVERRIDE, ENABLE), |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 162 | mc_make_sec_cfg(VIW, NON_SECURE, OVERRIDE, ENABLE), |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 163 | mc_make_sec_cfg(AXISR, SECURE, NO_OVERRIDE, DISABLE), |
| 164 | mc_make_sec_cfg(SDMMCW, NON_SECURE, OVERRIDE, ENABLE), |
| 165 | mc_make_sec_cfg(BPMPDMAW, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 166 | mc_make_sec_cfg(ISPRA, NON_SECURE, OVERRIDE, ENABLE), |
| 167 | mc_make_sec_cfg(NVDECSWR, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 168 | mc_make_sec_cfg(XUSB_DEVW, NON_SECURE, OVERRIDE, ENABLE), |
| 169 | mc_make_sec_cfg(NVDECSRD, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 170 | mc_make_sec_cfg(MPCOREW, NON_SECURE, OVERRIDE, ENABLE), |
| 171 | mc_make_sec_cfg(NVDISPLAYR, NON_SECURE, OVERRIDE, ENABLE), |
| 172 | mc_make_sec_cfg(BPMPDMAR, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 173 | mc_make_sec_cfg(NVJPGSWR, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 174 | mc_make_sec_cfg(NVDECSRD1, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 175 | mc_make_sec_cfg(TSECSRD, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 176 | mc_make_sec_cfg(NVJPGSRD, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 177 | mc_make_sec_cfg(SDMMCWA, NON_SECURE, OVERRIDE, ENABLE), |
Varun Wadekar | de729d6 | 2016-02-17 10:01:28 -0800 | [diff] [blame] | 178 | mc_make_sec_cfg(SCER, NON_SECURE, NO_OVERRIDE, ENABLE), |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 179 | mc_make_sec_cfg(XUSB_HOSTR, NON_SECURE, OVERRIDE, ENABLE), |
| 180 | mc_make_sec_cfg(VICSRD, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 181 | mc_make_sec_cfg(AONDMAR, NON_SECURE, OVERRIDE, ENABLE), |
| 182 | mc_make_sec_cfg(AONW, NON_SECURE, OVERRIDE, ENABLE), |
| 183 | mc_make_sec_cfg(SDMMCRA, NON_SECURE, OVERRIDE, ENABLE), |
| 184 | mc_make_sec_cfg(HOST1XDMAR, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 185 | mc_make_sec_cfg(EQOSR, NON_SECURE, OVERRIDE, ENABLE), |
| 186 | mc_make_sec_cfg(SATAR, NON_SECURE, OVERRIDE, ENABLE), |
| 187 | mc_make_sec_cfg(BPMPR, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 188 | mc_make_sec_cfg(HDAR, NON_SECURE, OVERRIDE, ENABLE), |
| 189 | mc_make_sec_cfg(SDMMCRAB, NON_SECURE, OVERRIDE, ENABLE), |
| 190 | mc_make_sec_cfg(ETRR, NON_SECURE, OVERRIDE, ENABLE), |
| 191 | mc_make_sec_cfg(AONR, NON_SECURE, OVERRIDE, ENABLE), |
Varun Wadekar | 0012d05 | 2016-04-19 14:22:13 -0700 | [diff] [blame] | 192 | mc_make_sec_cfg(SESRD, NON_SECURE, NO_OVERRIDE, ENABLE), |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 193 | mc_make_sec_cfg(NVENCSRD, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 194 | mc_make_sec_cfg(GPUSWR, SECURE, NO_OVERRIDE, DISABLE), |
| 195 | mc_make_sec_cfg(TSECSWRB, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 196 | mc_make_sec_cfg(ISPWB, NON_SECURE, OVERRIDE, ENABLE), |
| 197 | mc_make_sec_cfg(GPUSRD2, SECURE, NO_OVERRIDE, DISABLE), |
Varun Wadekar | 9610573 | 2016-03-28 14:28:09 -0700 | [diff] [blame] | 198 | #if ENABLE_CHIP_VERIFICATION_HARNESS |
| 199 | mc_make_sec_cfg(APEDMAW, NON_SECURE, OVERRIDE, ENABLE), |
| 200 | mc_make_sec_cfg(APER, NON_SECURE, OVERRIDE, ENABLE), |
| 201 | mc_make_sec_cfg(APEW, NON_SECURE, OVERRIDE, ENABLE), |
| 202 | mc_make_sec_cfg(APEDMAR, NON_SECURE, OVERRIDE, ENABLE), |
| 203 | #else |
| 204 | mc_make_sec_cfg(APEDMAW, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 205 | mc_make_sec_cfg(APER, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 206 | mc_make_sec_cfg(APEW, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 207 | mc_make_sec_cfg(APEDMAR, NON_SECURE, NO_OVERRIDE, ENABLE), |
| 208 | #endif |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 209 | }; |
| 210 | |
Varun Wadekar | c9ac3e4 | 2016-02-17 15:07:49 -0800 | [diff] [blame] | 211 | const static mc_txn_override_cfg_t mc_override_cfgs[] = { |
| 212 | mc_make_txn_override_cfg(BPMPW, CGID_TAG_ADR), |
| 213 | mc_make_txn_override_cfg(EQOSW, CGID_TAG_ADR), |
| 214 | mc_make_txn_override_cfg(NVJPGSWR, CGID_TAG_ADR), |
| 215 | mc_make_txn_override_cfg(SDMMCWAA, CGID_TAG_ADR), |
| 216 | mc_make_txn_override_cfg(MPCOREW, CGID_TAG_ADR), |
| 217 | mc_make_txn_override_cfg(SCEDMAW, CGID_TAG_ADR), |
| 218 | mc_make_txn_override_cfg(SDMMCW, CGID_TAG_ADR), |
| 219 | mc_make_txn_override_cfg(AXISW, CGID_TAG_ADR), |
| 220 | mc_make_txn_override_cfg(TSECSWR, CGID_TAG_ADR), |
| 221 | mc_make_txn_override_cfg(GPUSWR, CGID_TAG_ADR), |
| 222 | mc_make_txn_override_cfg(XUSB_HOSTW, CGID_TAG_ADR), |
| 223 | mc_make_txn_override_cfg(TSECSWRB, CGID_TAG_ADR), |
| 224 | mc_make_txn_override_cfg(GPUSWR2, CGID_TAG_ADR), |
| 225 | mc_make_txn_override_cfg(AONDMAW, CGID_TAG_ADR), |
| 226 | mc_make_txn_override_cfg(AONW, CGID_TAG_ADR), |
| 227 | mc_make_txn_override_cfg(SESWR, CGID_TAG_ADR), |
| 228 | mc_make_txn_override_cfg(BPMPDMAW, CGID_TAG_ADR), |
| 229 | mc_make_txn_override_cfg(SDMMCWA, CGID_TAG_ADR), |
| 230 | mc_make_txn_override_cfg(HDAW, CGID_TAG_ADR), |
| 231 | mc_make_txn_override_cfg(NVDECSWR, CGID_TAG_ADR), |
| 232 | mc_make_txn_override_cfg(UFSHCW, CGID_TAG_ADR), |
| 233 | mc_make_txn_override_cfg(SATAW, CGID_TAG_ADR), |
| 234 | mc_make_txn_override_cfg(ETRW, CGID_TAG_ADR), |
| 235 | mc_make_txn_override_cfg(VICSWR, CGID_TAG_ADR), |
| 236 | mc_make_txn_override_cfg(NVENCSWR, CGID_TAG_ADR), |
| 237 | mc_make_txn_override_cfg(SDMMCWAB, CGID_TAG_ADR), |
| 238 | mc_make_txn_override_cfg(ISPWB, CGID_TAG_ADR), |
| 239 | mc_make_txn_override_cfg(APEW, CGID_TAG_ADR), |
| 240 | mc_make_txn_override_cfg(XUSB_DEVW, CGID_TAG_ADR), |
| 241 | mc_make_txn_override_cfg(AFIW, CGID_TAG_ADR), |
| 242 | mc_make_txn_override_cfg(SCEW, CGID_TAG_ADR), |
| 243 | }; |
| 244 | |
Varun Wadekar | a0f2697 | 2016-03-11 17:18:51 -0800 | [diff] [blame] | 245 | static void tegra_memctrl_reconfig_mss_clients(void) |
| 246 | { |
| 247 | #if ENABLE_ROC_FOR_ORDERING_CLIENT_REQUESTS |
| 248 | uint32_t val, wdata_0, wdata_1; |
| 249 | |
| 250 | /* |
| 251 | * Assert Memory Controller's HOTRESET_FLUSH_ENABLE signal for |
| 252 | * boot and strongly ordered MSS clients to flush existing memory |
| 253 | * traffic and stall future requests. |
| 254 | */ |
| 255 | val = tegra_mc_read_32(MC_CLIENT_HOTRESET_CTRL0); |
| 256 | assert(val == MC_CLIENT_HOTRESET_CTRL0_RESET_VAL); |
| 257 | |
| 258 | wdata_0 = MC_CLIENT_HOTRESET_CTRL0_AFI_FLUSH_ENB | |
| 259 | MC_CLIENT_HOTRESET_CTRL0_HDA_FLUSH_ENB | |
| 260 | MC_CLIENT_HOTRESET_CTRL0_SATA_FLUSH_ENB | |
| 261 | MC_CLIENT_HOTRESET_CTRL0_XUSB_HOST_FLUSH_ENB | |
| 262 | MC_CLIENT_HOTRESET_CTRL0_XUSB_DEV_FLUSH_ENB; |
| 263 | tegra_mc_write_32(MC_CLIENT_HOTRESET_CTRL0, wdata_0); |
| 264 | |
| 265 | /* Wait for HOTRESET STATUS to indicate FLUSH_DONE */ |
| 266 | do { |
| 267 | val = tegra_mc_read_32(MC_CLIENT_HOTRESET_STATUS0); |
| 268 | } while ((val & wdata_0) != wdata_0); |
| 269 | |
| 270 | /* Wait one more time due to SW WAR for known legacy issue */ |
| 271 | do { |
| 272 | val = tegra_mc_read_32(MC_CLIENT_HOTRESET_STATUS0); |
| 273 | } while ((val & wdata_0) != wdata_0); |
| 274 | |
| 275 | val = tegra_mc_read_32(MC_CLIENT_HOTRESET_CTRL1); |
| 276 | assert(val == MC_CLIENT_HOTRESET_CTRL1_RESET_VAL); |
| 277 | |
| 278 | wdata_1 = MC_CLIENT_HOTRESET_CTRL1_SDMMC4A_FLUSH_ENB | |
| 279 | MC_CLIENT_HOTRESET_CTRL1_APE_FLUSH_ENB | |
| 280 | MC_CLIENT_HOTRESET_CTRL1_SE_FLUSH_ENB | |
| 281 | MC_CLIENT_HOTRESET_CTRL1_ETR_FLUSH_ENB | |
| 282 | MC_CLIENT_HOTRESET_CTRL1_AXIS_FLUSH_ENB | |
| 283 | MC_CLIENT_HOTRESET_CTRL1_EQOS_FLUSH_ENB | |
| 284 | MC_CLIENT_HOTRESET_CTRL1_UFSHC_FLUSH_ENB | |
| 285 | MC_CLIENT_HOTRESET_CTRL1_BPMP_FLUSH_ENB | |
| 286 | MC_CLIENT_HOTRESET_CTRL1_AON_FLUSH_ENB | |
| 287 | MC_CLIENT_HOTRESET_CTRL1_SCE_FLUSH_ENB; |
| 288 | tegra_mc_write_32(MC_CLIENT_HOTRESET_CTRL1, wdata_1); |
| 289 | |
| 290 | /* Wait for HOTRESET STATUS to indicate FLUSH_DONE */ |
| 291 | do { |
| 292 | val = tegra_mc_read_32(MC_CLIENT_HOTRESET_STATUS1); |
| 293 | } while ((val & wdata_1) != wdata_1); |
| 294 | |
| 295 | /* Wait one more time due to SW WAR for known legacy issue */ |
| 296 | do { |
| 297 | val = tegra_mc_read_32(MC_CLIENT_HOTRESET_STATUS1); |
| 298 | } while ((val & wdata_1) != wdata_1); |
| 299 | |
| 300 | /* |
| 301 | * Change MEMTYPE_OVERRIDE from SO_DEV -> PASSTHRU for boot and |
| 302 | * strongly ordered MSS clients. ROC needs to be single point |
| 303 | * of control on overriding the memory type. So, remove TSA's |
| 304 | * memtype override. |
| 305 | */ |
| 306 | mc_set_tsa_passthrough(AFIW); |
| 307 | mc_set_tsa_passthrough(HDAW); |
| 308 | mc_set_tsa_passthrough(SATAW); |
| 309 | mc_set_tsa_passthrough(XUSB_HOSTW); |
| 310 | mc_set_tsa_passthrough(XUSB_DEVW); |
| 311 | mc_set_tsa_passthrough(SDMMCWAB); |
| 312 | mc_set_tsa_passthrough(APEDMAW); |
| 313 | mc_set_tsa_passthrough(SESWR); |
| 314 | mc_set_tsa_passthrough(ETRW); |
| 315 | mc_set_tsa_passthrough(AXISW); |
| 316 | mc_set_tsa_passthrough(EQOSW); |
| 317 | mc_set_tsa_passthrough(UFSHCW); |
| 318 | mc_set_tsa_passthrough(BPMPDMAW); |
| 319 | mc_set_tsa_passthrough(AONDMAW); |
| 320 | mc_set_tsa_passthrough(SCEDMAW); |
| 321 | |
| 322 | /* |
| 323 | * Change COH_PATH_OVERRIDE_SO_DEV from NO_OVERRIDE -> FORCE_COHERENT |
| 324 | * for boot and strongly ordered MSS clients. This steers all sodev |
| 325 | * transactions to ROC. |
| 326 | * |
| 327 | * Change AXID_OVERRIDE/AXID_OVERRIDE_SO_DEV only for some clients |
| 328 | * whose AXI IDs we know and trust. |
| 329 | */ |
| 330 | |
| 331 | /* Match AFIW */ |
| 332 | mc_set_forced_coherent_so_dev_cfg(AFIR); |
| 333 | |
| 334 | /* |
| 335 | * See bug 200131110 comment #35 - there are no normal requests |
| 336 | * and AWID for SO/DEV requests is hardcoded in RTL for a |
| 337 | * particular PCIE controller |
| 338 | */ |
| 339 | mc_set_forced_coherent_so_dev_cfg(AFIW); |
| 340 | mc_set_forced_coherent_cfg(HDAR); |
| 341 | mc_set_forced_coherent_cfg(HDAW); |
| 342 | mc_set_forced_coherent_cfg(SATAR); |
| 343 | mc_set_forced_coherent_cfg(SATAW); |
| 344 | mc_set_forced_coherent_cfg(XUSB_HOSTR); |
| 345 | mc_set_forced_coherent_cfg(XUSB_HOSTW); |
| 346 | mc_set_forced_coherent_cfg(XUSB_DEVR); |
| 347 | mc_set_forced_coherent_cfg(XUSB_DEVW); |
| 348 | mc_set_forced_coherent_cfg(SDMMCRAB); |
| 349 | mc_set_forced_coherent_cfg(SDMMCWAB); |
| 350 | |
| 351 | /* Match APEDMAW */ |
| 352 | mc_set_forced_coherent_axid_so_dev_cfg(APEDMAR); |
| 353 | |
| 354 | /* |
| 355 | * See bug 200131110 comment #35 - AWID for normal requests |
| 356 | * is 0x80 and AWID for SO/DEV requests is 0x01 |
| 357 | */ |
| 358 | mc_set_forced_coherent_axid_so_dev_cfg(APEDMAW); |
| 359 | mc_set_forced_coherent_cfg(SESRD); |
| 360 | mc_set_forced_coherent_cfg(SESWR); |
| 361 | mc_set_forced_coherent_cfg(ETRR); |
| 362 | mc_set_forced_coherent_cfg(ETRW); |
| 363 | mc_set_forced_coherent_cfg(AXISR); |
| 364 | mc_set_forced_coherent_cfg(AXISW); |
| 365 | mc_set_forced_coherent_cfg(EQOSR); |
| 366 | mc_set_forced_coherent_cfg(EQOSW); |
| 367 | mc_set_forced_coherent_cfg(UFSHCR); |
| 368 | mc_set_forced_coherent_cfg(UFSHCW); |
| 369 | mc_set_forced_coherent_cfg(BPMPDMAR); |
| 370 | mc_set_forced_coherent_cfg(BPMPDMAW); |
| 371 | mc_set_forced_coherent_cfg(AONDMAR); |
| 372 | mc_set_forced_coherent_cfg(AONDMAW); |
| 373 | mc_set_forced_coherent_cfg(SCEDMAR); |
| 374 | mc_set_forced_coherent_cfg(SCEDMAW); |
| 375 | |
| 376 | /* |
| 377 | * At this point, ordering can occur at ROC. So, remove PCFIFO's |
| 378 | * control over ordering requests. |
| 379 | * |
| 380 | * Change PCFIFO_*_ORDERED_CLIENT from ORDERED -> UNORDERED for |
| 381 | * boot and strongly ordered MSS clients |
| 382 | */ |
| 383 | val = MC_PCFIFO_CLIENT_CONFIG1_RESET_VAL & |
| 384 | mc_set_pcfifo_unordered_boot_so_mss(1, AFIW) & |
| 385 | mc_set_pcfifo_unordered_boot_so_mss(1, HDAW) & |
| 386 | mc_set_pcfifo_unordered_boot_so_mss(1, SATAW); |
| 387 | tegra_mc_write_32(MC_PCFIFO_CLIENT_CONFIG1, val); |
| 388 | |
| 389 | val = MC_PCFIFO_CLIENT_CONFIG2_RESET_VAL & |
| 390 | mc_set_pcfifo_unordered_boot_so_mss(2, XUSB_HOSTW) & |
| 391 | mc_set_pcfifo_unordered_boot_so_mss(2, XUSB_DEVW); |
| 392 | tegra_mc_write_32(MC_PCFIFO_CLIENT_CONFIG2, val); |
| 393 | |
| 394 | val = MC_PCFIFO_CLIENT_CONFIG3_RESET_VAL & |
| 395 | mc_set_pcfifo_unordered_boot_so_mss(3, SDMMCWAB); |
| 396 | tegra_mc_write_32(MC_PCFIFO_CLIENT_CONFIG3, val); |
| 397 | |
| 398 | val = MC_PCFIFO_CLIENT_CONFIG4_RESET_VAL & |
| 399 | mc_set_pcfifo_unordered_boot_so_mss(4, SESWR) & |
| 400 | mc_set_pcfifo_unordered_boot_so_mss(4, ETRW) & |
| 401 | mc_set_pcfifo_unordered_boot_so_mss(4, AXISW) & |
| 402 | mc_set_pcfifo_unordered_boot_so_mss(4, EQOSW) & |
| 403 | mc_set_pcfifo_unordered_boot_so_mss(4, UFSHCW) & |
| 404 | mc_set_pcfifo_unordered_boot_so_mss(4, BPMPDMAW) & |
| 405 | mc_set_pcfifo_unordered_boot_so_mss(4, AONDMAW) & |
| 406 | mc_set_pcfifo_unordered_boot_so_mss(4, SCEDMAW); |
| 407 | tegra_mc_write_32(MC_PCFIFO_CLIENT_CONFIG4, val); |
| 408 | |
| 409 | val = MC_PCFIFO_CLIENT_CONFIG5_RESET_VAL & |
| 410 | mc_set_pcfifo_unordered_boot_so_mss(5, APEDMAW); |
| 411 | tegra_mc_write_32(MC_PCFIFO_CLIENT_CONFIG5, val); |
| 412 | |
| 413 | /* |
| 414 | * At this point, ordering can occur at ROC. SMMU need not |
| 415 | * reorder any requests. |
| 416 | * |
| 417 | * Change SMMU_*_ORDERED_CLIENT from ORDERED -> UNORDERED |
| 418 | * for boot and strongly ordered MSS clients |
| 419 | */ |
| 420 | val = MC_SMMU_CLIENT_CONFIG1_RESET_VAL & |
| 421 | mc_set_smmu_unordered_boot_so_mss(1, AFIW) & |
| 422 | mc_set_smmu_unordered_boot_so_mss(1, HDAW) & |
| 423 | mc_set_smmu_unordered_boot_so_mss(1, SATAW); |
| 424 | tegra_mc_write_32(MC_SMMU_CLIENT_CONFIG1, val); |
| 425 | |
| 426 | val = MC_SMMU_CLIENT_CONFIG2_RESET_VAL & |
| 427 | mc_set_smmu_unordered_boot_so_mss(2, XUSB_HOSTW) & |
| 428 | mc_set_smmu_unordered_boot_so_mss(2, XUSB_DEVW); |
| 429 | tegra_mc_write_32(MC_SMMU_CLIENT_CONFIG2, val); |
| 430 | |
| 431 | val = MC_SMMU_CLIENT_CONFIG3_RESET_VAL & |
| 432 | mc_set_smmu_unordered_boot_so_mss(3, SDMMCWAB); |
| 433 | tegra_mc_write_32(MC_SMMU_CLIENT_CONFIG3, val); |
| 434 | |
| 435 | val = MC_SMMU_CLIENT_CONFIG4_RESET_VAL & |
| 436 | mc_set_smmu_unordered_boot_so_mss(4, SESWR) & |
| 437 | mc_set_smmu_unordered_boot_so_mss(4, ETRW) & |
| 438 | mc_set_smmu_unordered_boot_so_mss(4, AXISW) & |
| 439 | mc_set_smmu_unordered_boot_so_mss(4, EQOSW) & |
| 440 | mc_set_smmu_unordered_boot_so_mss(4, UFSHCW) & |
| 441 | mc_set_smmu_unordered_boot_so_mss(4, BPMPDMAW) & |
| 442 | mc_set_smmu_unordered_boot_so_mss(4, AONDMAW) & |
| 443 | mc_set_smmu_unordered_boot_so_mss(4, SCEDMAW); |
| 444 | tegra_mc_write_32(MC_SMMU_CLIENT_CONFIG4, val); |
| 445 | |
| 446 | val = MC_SMMU_CLIENT_CONFIG5_RESET_VAL & |
| 447 | mc_set_smmu_unordered_boot_so_mss(5, APEDMAW); |
| 448 | tegra_mc_write_32(MC_SMMU_CLIENT_CONFIG5, val); |
| 449 | |
| 450 | /* |
| 451 | * Deassert HOTRESET FLUSH_ENABLE for boot and strongly ordered MSS |
| 452 | * clients to allow memory traffic from all clients to start passing |
| 453 | * through ROC |
| 454 | */ |
| 455 | val = tegra_mc_read_32(MC_CLIENT_HOTRESET_CTRL0); |
| 456 | assert(val == wdata_0); |
| 457 | |
| 458 | wdata_0 = MC_CLIENT_HOTRESET_CTRL0_RESET_VAL; |
| 459 | tegra_mc_write_32(MC_CLIENT_HOTRESET_CTRL0, wdata_0); |
| 460 | |
| 461 | /* Wait for HOTRESET STATUS to indicate FLUSH_DONE */ |
| 462 | do { |
| 463 | val = tegra_mc_read_32(MC_CLIENT_HOTRESET_STATUS0); |
| 464 | } while ((val & wdata_0) != wdata_0); |
| 465 | |
| 466 | /* Wait one more time due to SW WAR for known legacy issue */ |
| 467 | do { |
| 468 | val = tegra_mc_read_32(MC_CLIENT_HOTRESET_STATUS0); |
| 469 | } while ((val & wdata_0) != wdata_0); |
| 470 | |
| 471 | val = tegra_mc_read_32(MC_CLIENT_HOTRESET_CTRL1); |
| 472 | assert(val == wdata_1); |
| 473 | |
| 474 | wdata_1 = MC_CLIENT_HOTRESET_CTRL1_RESET_VAL; |
| 475 | tegra_mc_write_32(MC_CLIENT_HOTRESET_CTRL1, wdata_1); |
| 476 | |
| 477 | /* Wait for HOTRESET STATUS to indicate FLUSH_DONE */ |
| 478 | do { |
| 479 | val = tegra_mc_read_32(MC_CLIENT_HOTRESET_STATUS1); |
| 480 | } while ((val & wdata_1) != wdata_1); |
| 481 | |
| 482 | /* Wait one more time due to SW WAR for known legacy issue */ |
| 483 | do { |
| 484 | val = tegra_mc_read_32(MC_CLIENT_HOTRESET_STATUS1); |
| 485 | } while ((val & wdata_1) != wdata_1); |
| 486 | |
| 487 | #endif |
| 488 | } |
| 489 | |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 490 | /* |
Varun Wadekar | 87e44ff | 2016-03-03 13:22:39 -0800 | [diff] [blame] | 491 | * Init Memory controller during boot. |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 492 | */ |
| 493 | void tegra_memctrl_setup(void) |
| 494 | { |
| 495 | uint32_t val; |
| 496 | uint32_t num_overrides = sizeof(streamid_overrides) / sizeof(uint32_t); |
| 497 | uint32_t num_sec_cfgs = sizeof(sec_cfgs) / sizeof(mc_streamid_security_cfg_t); |
Varun Wadekar | c9ac3e4 | 2016-02-17 15:07:49 -0800 | [diff] [blame] | 498 | uint32_t num_txn_overrides = sizeof(mc_override_cfgs) / sizeof(mc_txn_override_cfg_t); |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 499 | int i; |
| 500 | |
| 501 | INFO("Tegra Memory Controller (v2)\n"); |
| 502 | |
| 503 | /* Program the SMMU pagesize */ |
Varun Wadekar | 87e44ff | 2016-03-03 13:22:39 -0800 | [diff] [blame] | 504 | tegra_smmu_init(); |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 505 | |
| 506 | /* Program all the Stream ID overrides */ |
| 507 | for (i = 0; i < num_overrides; i++) |
| 508 | tegra_mc_streamid_write_32(streamid_overrides[i], |
| 509 | MC_STREAM_ID_MAX); |
| 510 | |
| 511 | /* Program the security config settings for all Stream IDs */ |
| 512 | for (i = 0; i < num_sec_cfgs; i++) { |
| 513 | val = sec_cfgs[i].override_enable << 16 | |
| 514 | sec_cfgs[i].override_client_inputs << 8 | |
| 515 | sec_cfgs[i].override_client_ns_flag << 0; |
| 516 | tegra_mc_streamid_write_32(sec_cfgs[i].offset, val); |
| 517 | } |
| 518 | |
| 519 | /* |
| 520 | * All requests at boot time, and certain requests during |
| 521 | * normal run time, are physically addressed and must bypass |
| 522 | * the SMMU. The client hub logic implements a hardware bypass |
| 523 | * path around the Translation Buffer Units (TBU). During |
| 524 | * boot-time, the SMMU_BYPASS_CTRL register (which defaults to |
| 525 | * TBU_BYPASS mode) will be used to steer all requests around |
| 526 | * the uninitialized TBUs. During normal operation, this register |
| 527 | * is locked into TBU_BYPASS_SID config, which routes requests |
| 528 | * with special StreamID 0x7f on the bypass path and all others |
| 529 | * through the selected TBU. This is done to disable SMMU Bypass |
| 530 | * mode, as it could be used to circumvent SMMU security checks. |
| 531 | */ |
| 532 | tegra_mc_write_32(MC_SMMU_BYPASS_CONFIG, |
| 533 | MC_SMMU_BYPASS_CONFIG_SETTINGS); |
| 534 | |
Varun Wadekar | c9ac3e4 | 2016-02-17 15:07:49 -0800 | [diff] [blame] | 535 | /* |
Varun Wadekar | a0f2697 | 2016-03-11 17:18:51 -0800 | [diff] [blame] | 536 | * Re-configure MSS to allow ROC to deal with ordering of the |
| 537 | * Memory Controller traffic. This is needed as the Memory Controller |
| 538 | * boots with MSS having all control, but ROC provides a performance |
| 539 | * boost as compared to MSS. |
| 540 | */ |
| 541 | tegra_memctrl_reconfig_mss_clients(); |
| 542 | |
| 543 | /* |
Varun Wadekar | c9ac3e4 | 2016-02-17 15:07:49 -0800 | [diff] [blame] | 544 | * Set the MC_TXN_OVERRIDE registers for write clients. |
| 545 | */ |
Varun Wadekar | e81177d | 2016-07-18 17:43:41 -0700 | [diff] [blame] | 546 | if (!tegra_platform_is_silicon() || |
| 547 | (tegra_platform_is_silicon() && tegra_get_chipid_minor() == 1)) { |
Varun Wadekar | c9ac3e4 | 2016-02-17 15:07:49 -0800 | [diff] [blame] | 548 | |
| 549 | /* GPU and NVENC settings for rev. A01 */ |
| 550 | val = tegra_mc_read_32(MC_TXN_OVERRIDE_CONFIG_GPUSWR); |
| 551 | val &= ~MC_TXN_OVERRIDE_CGID_TAG_MASK; |
| 552 | tegra_mc_write_32(MC_TXN_OVERRIDE_CONFIG_GPUSWR, |
| 553 | val | MC_TXN_OVERRIDE_CGID_TAG_ZERO); |
| 554 | |
| 555 | val = tegra_mc_read_32(MC_TXN_OVERRIDE_CONFIG_GPUSWR2); |
| 556 | val &= ~MC_TXN_OVERRIDE_CGID_TAG_MASK; |
| 557 | tegra_mc_write_32(MC_TXN_OVERRIDE_CONFIG_GPUSWR2, |
| 558 | val | MC_TXN_OVERRIDE_CGID_TAG_ZERO); |
| 559 | |
| 560 | val = tegra_mc_read_32(MC_TXN_OVERRIDE_CONFIG_NVENCSWR); |
| 561 | val &= ~MC_TXN_OVERRIDE_CGID_TAG_MASK; |
| 562 | tegra_mc_write_32(MC_TXN_OVERRIDE_CONFIG_NVENCSWR, |
| 563 | val | MC_TXN_OVERRIDE_CGID_TAG_CLIENT_AXI_ID); |
| 564 | |
| 565 | } else { |
| 566 | |
| 567 | /* settings for rev. A02 */ |
| 568 | for (i = 0; i < num_txn_overrides; i++) { |
| 569 | val = tegra_mc_read_32(mc_override_cfgs[i].offset); |
| 570 | val &= ~MC_TXN_OVERRIDE_CGID_TAG_MASK; |
| 571 | tegra_mc_write_32(mc_override_cfgs[i].offset, |
| 572 | val | mc_override_cfgs[i].cgid_tag); |
| 573 | } |
| 574 | |
| 575 | } |
Varun Wadekar | 87e44ff | 2016-03-03 13:22:39 -0800 | [diff] [blame] | 576 | } |
Varun Wadekar | c9ac3e4 | 2016-02-17 15:07:49 -0800 | [diff] [blame] | 577 | |
Varun Wadekar | 87e44ff | 2016-03-03 13:22:39 -0800 | [diff] [blame] | 578 | /* |
| 579 | * Restore Memory Controller settings after "System Suspend" |
| 580 | */ |
| 581 | void tegra_memctrl_restore_settings(void) |
| 582 | { |
Varun Wadekar | a0f2697 | 2016-03-11 17:18:51 -0800 | [diff] [blame] | 583 | /* |
| 584 | * Re-configure MSS to allow ROC to deal with ordering of the |
| 585 | * Memory Controller traffic. This is needed as the Memory Controller |
| 586 | * resets during System Suspend with MSS having all control, but ROC |
| 587 | * provides a performance boost as compared to MSS. |
| 588 | */ |
| 589 | tegra_memctrl_reconfig_mss_clients(); |
| 590 | |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 591 | /* video memory carveout region */ |
| 592 | if (video_mem_base) { |
| 593 | tegra_mc_write_32(MC_VIDEO_PROTECT_BASE_LO, |
| 594 | (uint32_t)video_mem_base); |
| 595 | tegra_mc_write_32(MC_VIDEO_PROTECT_BASE_HI, |
| 596 | (uint32_t)(video_mem_base >> 32)); |
Varun Wadekar | 7058aee | 2016-04-25 09:01:46 -0700 | [diff] [blame] | 597 | 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] | 598 | |
| 599 | /* |
| 600 | * MCE propogates the VideoMem configuration values across the |
| 601 | * CCPLEX. |
| 602 | */ |
| 603 | mce_update_gsc_videomem(); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | /* |
| 608 | * Secure the BL31 DRAM aperture. |
| 609 | * |
| 610 | * phys_base = physical base of TZDRAM aperture |
| 611 | * size_in_bytes = size of aperture in bytes |
| 612 | */ |
| 613 | void tegra_memctrl_tzdram_setup(uint64_t phys_base, uint32_t size_in_bytes) |
| 614 | { |
| 615 | /* |
| 616 | * Setup the Memory controller to allow only secure accesses to |
| 617 | * the TZDRAM carveout |
| 618 | */ |
| 619 | INFO("Configuring TrustZone DRAM Memory Carveout\n"); |
| 620 | |
| 621 | tegra_mc_write_32(MC_SECURITY_CFG0_0, (uint32_t)phys_base); |
| 622 | tegra_mc_write_32(MC_SECURITY_CFG3_0, (uint32_t)(phys_base >> 32)); |
| 623 | tegra_mc_write_32(MC_SECURITY_CFG1_0, size_in_bytes >> 20); |
| 624 | |
| 625 | /* |
| 626 | * MCE propogates the security configuration values across the |
| 627 | * CCPLEX. |
| 628 | */ |
| 629 | mce_update_gsc_tzdram(); |
| 630 | } |
| 631 | |
| 632 | /* |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 633 | * Secure the BL31 TZRAM aperture. |
| 634 | * |
| 635 | * phys_base = physical base of TZRAM aperture |
| 636 | * size_in_bytes = size of aperture in bytes |
| 637 | */ |
| 638 | void tegra_memctrl_tzram_setup(uint64_t phys_base, uint32_t size_in_bytes) |
| 639 | { |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 640 | uint32_t index; |
| 641 | uint32_t total_128kb_blocks = size_in_bytes >> 17; |
| 642 | uint32_t residual_4kb_blocks = (size_in_bytes & 0x1FFFF) >> 12; |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 643 | uint32_t val; |
| 644 | |
| 645 | /* |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 646 | * Reset the access configuration registers to restrict access |
| 647 | * to the TZRAM aperture |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 648 | */ |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 649 | for (index = MC_TZRAM_CARVEOUT_CLIENT_ACCESS_CFG0; |
| 650 | index <= MC_TZRAM_CARVEOUT_FORCE_INTERNAL_ACCESS5; |
| 651 | index += 4) |
| 652 | tegra_mc_write_32(index, 0); |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 653 | |
| 654 | /* |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 655 | * Allow CPU read/write access to the aperture |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 656 | */ |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 657 | tegra_mc_write_32(MC_TZRAM_CARVEOUT_CLIENT_ACCESS_CFG1, |
| 658 | TZRAM_CARVEOUT_CPU_WRITE_ACCESS_BIT | |
| 659 | TZRAM_CARVEOUT_CPU_READ_ACCESS_BIT); |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 660 | |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 661 | /* |
| 662 | * Set the TZRAM base. TZRAM base must be 4k aligned, at least. |
| 663 | */ |
| 664 | assert(!(phys_base & 0xFFF)); |
| 665 | tegra_mc_write_32(MC_TZRAM_BASE_LO, (uint32_t)phys_base); |
| 666 | tegra_mc_write_32(MC_TZRAM_BASE_HI, |
| 667 | (uint32_t)(phys_base >> 32) & TZRAM_BASE_HI_MASK); |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 668 | |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 669 | /* |
| 670 | * Set the TZRAM size |
| 671 | * |
| 672 | * total size = (number of 128KB blocks) + (number of remaining 4KB |
| 673 | * blocks) |
| 674 | * |
| 675 | */ |
| 676 | val = (residual_4kb_blocks << TZRAM_SIZE_RANGE_4KB_SHIFT) | |
| 677 | total_128kb_blocks; |
| 678 | tegra_mc_write_32(MC_TZRAM_SIZE, val); |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 679 | |
Varun Wadekar | e6d4322 | 2016-05-25 16:35:04 -0700 | [diff] [blame] | 680 | /* |
| 681 | * Lock the configuration settings by disabling TZ-only lock |
| 682 | * and locking the configuration against any future changes |
| 683 | * at all. |
| 684 | */ |
| 685 | val = tegra_mc_read_32(MC_TZRAM_CARVEOUT_CFG); |
| 686 | val &= ~TZRAM_ENABLE_TZ_LOCK_BIT; |
| 687 | val |= TZRAM_LOCK_CFG_SETTINGS_BIT; |
| 688 | tegra_mc_write_32(MC_TZRAM_CARVEOUT_CFG, val); |
Varun Wadekar | 13e7dc4 | 2015-12-30 15:15:08 -0800 | [diff] [blame] | 689 | |
| 690 | /* |
| 691 | * MCE propogates the security configuration values across the |
| 692 | * CCPLEX. |
| 693 | */ |
| 694 | mce_update_gsc_tzram(); |
| 695 | } |
| 696 | |
| 697 | /* |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 698 | * Program the Video Memory carveout region |
| 699 | * |
| 700 | * phys_base = physical base of aperture |
| 701 | * size_in_bytes = size of aperture in bytes |
| 702 | */ |
| 703 | void tegra_memctrl_videomem_setup(uint64_t phys_base, uint32_t size_in_bytes) |
| 704 | { |
Varun Wadekar | e60f1bf | 2016-02-17 10:10:50 -0800 | [diff] [blame] | 705 | uint32_t regval; |
| 706 | |
| 707 | /* |
| 708 | * The GPU is the user of the Video Memory region. In order to |
| 709 | * transition to the new memory region smoothly, we program the |
| 710 | * new base/size ONLY if the GPU is in reset mode. |
| 711 | */ |
| 712 | regval = mmio_read_32(TEGRA_CAR_RESET_BASE + TEGRA_GPU_RESET_REG_OFFSET); |
| 713 | if ((regval & GPU_RESET_BIT) == 0) { |
| 714 | ERROR("GPU not in reset! Video Memory setup failed\n"); |
| 715 | return; |
| 716 | } |
| 717 | |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 718 | /* |
| 719 | * Setup the Memory controller to restrict CPU accesses to the Video |
| 720 | * Memory region |
| 721 | */ |
| 722 | INFO("Configuring Video Memory Carveout\n"); |
| 723 | |
| 724 | tegra_mc_write_32(MC_VIDEO_PROTECT_BASE_LO, (uint32_t)phys_base); |
| 725 | tegra_mc_write_32(MC_VIDEO_PROTECT_BASE_HI, |
| 726 | (uint32_t)(phys_base >> 32)); |
Varun Wadekar | 7058aee | 2016-04-25 09:01:46 -0700 | [diff] [blame] | 727 | 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] | 728 | |
| 729 | /* store new values */ |
| 730 | video_mem_base = phys_base; |
Varun Wadekar | 7058aee | 2016-04-25 09:01:46 -0700 | [diff] [blame] | 731 | video_mem_size_mb = size_in_bytes >> 20; |
Varun Wadekar | cd5a2f5 | 2015-09-20 15:08:22 +0530 | [diff] [blame] | 732 | |
| 733 | /* |
| 734 | * MCE propogates the VideoMem configuration values across the |
| 735 | * CCPLEX. |
| 736 | */ |
| 737 | mce_update_gsc_videomem(); |
| 738 | } |