blob: 4189b00b19cbbdc640c06c1b95221863cd10b5ca [file] [log] [blame]
Varun Wadekar3c959932016-03-03 13:09:08 -08001/*
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +01002 * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
Pritesh Raithatha75c94432018-08-03 15:48:15 +05303 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Varun Wadekar3c959932016-03-03 13:09:08 -08004 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar3c959932016-03-03 13:09:08 -08006 */
7
8#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <string.h>
10
Varun Wadekar93bed2a2016-03-18 13:07:33 -070011#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012
13#include <common/bl_common.h>
14#include <common/debug.h>
15
Varun Wadekar3c959932016-03-03 13:09:08 -080016#include <smmu.h>
Varun Wadekar82b0b182019-09-26 08:26:41 -070017#include <tegra_platform.h>
Varun Wadekar93bed2a2016-03-18 13:07:33 -070018#include <tegra_private.h>
Varun Wadekar3c959932016-03-03 13:09:08 -080019
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +010020extern void memcpy16(void *dest, const void *src, unsigned int length);
21
Pritesh Raithatha75c94432018-08-03 15:48:15 +053022#define SMMU_NUM_CONTEXTS 64U
23#define SMMU_CONTEXT_BANK_MAX_IDX 64U
Varun Wadekarea709c32016-04-20 17:14:15 -070024
Varun Wadekar82b0b182019-09-26 08:26:41 -070025#define MISMATCH_DETECTED 0x55AA55AAU
26
Varun Wadekar3c959932016-03-03 13:09:08 -080027/*
28 * Init SMMU during boot or "System Suspend" exit
29 */
30void tegra_smmu_init(void)
31{
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053032 uint32_t val, cb_idx, smmu_id, ctx_base;
Varun Wadekar82b0b182019-09-26 08:26:41 -070033 uint32_t num_smmu_devices = plat_get_num_smmu_devices();
Steven Kao7fd30f52017-07-25 11:29:46 +080034
Varun Wadekar82b0b182019-09-26 08:26:41 -070035 for (smmu_id = 0U; smmu_id < num_smmu_devices; smmu_id++) {
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053036 /* Program the SMMU pagesize and reset CACHE_LOCK bit */
37 val = tegra_smmu_read_32(smmu_id, SMMU_GSR0_SECURE_ACR);
38 val |= SMMU_GSR0_PGSIZE_64K;
Anthony Zhou0e07e452017-07-26 17:16:54 +080039 val &= (uint32_t)~SMMU_ACR_CACHE_LOCK_ENABLE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053040 tegra_smmu_write_32(smmu_id, SMMU_GSR0_SECURE_ACR, val);
Varun Wadekarea709c32016-04-20 17:14:15 -070041
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053042 /* reset CACHE LOCK bit for NS Aux. Config. Register */
43 val = tegra_smmu_read_32(smmu_id, SMMU_GNSR_ACR);
Anthony Zhou0e07e452017-07-26 17:16:54 +080044 val &= (uint32_t)~SMMU_ACR_CACHE_LOCK_ENABLE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053045 tegra_smmu_write_32(smmu_id, SMMU_GNSR_ACR, val);
Varun Wadekarea709c32016-04-20 17:14:15 -070046
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053047 /* disable TCU prefetch for all contexts */
48 ctx_base = (SMMU_GSR0_PGSIZE_64K * SMMU_NUM_CONTEXTS)
49 + SMMU_CBn_ACTLR;
Varun Wadekar82b0b182019-09-26 08:26:41 -070050 for (cb_idx = 0U; cb_idx < SMMU_CONTEXT_BANK_MAX_IDX; cb_idx++) {
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053051 val = tegra_smmu_read_32(smmu_id,
52 ctx_base + (SMMU_GSR0_PGSIZE_64K * cb_idx));
Anthony Zhou0e07e452017-07-26 17:16:54 +080053 val &= (uint32_t)~SMMU_CBn_ACTLR_CPRE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053054 tegra_smmu_write_32(smmu_id, ctx_base +
55 (SMMU_GSR0_PGSIZE_64K * cb_idx), val);
56 }
Varun Wadekarea709c32016-04-20 17:14:15 -070057
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053058 /* set CACHE LOCK bit for NS Aux. Config. Register */
59 val = tegra_smmu_read_32(smmu_id, SMMU_GNSR_ACR);
Anthony Zhou0e07e452017-07-26 17:16:54 +080060 val |= (uint32_t)SMMU_ACR_CACHE_LOCK_ENABLE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053061 tegra_smmu_write_32(smmu_id, SMMU_GNSR_ACR, val);
Varun Wadekarea709c32016-04-20 17:14:15 -070062
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053063 /* set CACHE LOCK bit for S Aux. Config. Register */
64 val = tegra_smmu_read_32(smmu_id, SMMU_GSR0_SECURE_ACR);
Anthony Zhou0e07e452017-07-26 17:16:54 +080065 val |= (uint32_t)SMMU_ACR_CACHE_LOCK_ENABLE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053066 tegra_smmu_write_32(smmu_id, SMMU_GSR0_SECURE_ACR, val);
67 }
Varun Wadekar3c959932016-03-03 13:09:08 -080068}
Varun Wadekar82b0b182019-09-26 08:26:41 -070069
70/*
71 * Verify SMMU settings have not been altered during boot
72 */
73void tegra_smmu_verify(void)
74{
75 uint32_t cb_idx, ctx_base, smmu_id, val;
76 uint32_t num_smmu_devices = plat_get_num_smmu_devices();
77 uint32_t mismatch = 0U;
78
79 for (smmu_id = 0U; smmu_id < num_smmu_devices; smmu_id++) {
80 /* check PGSIZE_64K bit inr S Aux. Config. Register */
81 val = tegra_smmu_read_32(smmu_id, SMMU_GSR0_SECURE_ACR);
82 if (0U == (val & SMMU_GSR0_PGSIZE_64K)) {
83 ERROR("%s: PGSIZE_64K Mismatch - smmu_id=%d, GSR0_SECURE_ACR=%x\n",
84 __func__, smmu_id, val);
85 mismatch = MISMATCH_DETECTED;
86 }
87
88 /* check CACHE LOCK bit in S Aux. Config. Register */
89 if (0U == (val & SMMU_ACR_CACHE_LOCK_ENABLE_BIT)) {
90 ERROR("%s: CACHE_LOCK Mismatch - smmu_id=%d, GSR0_SECURE_ACR=%x\n",
91 __func__, smmu_id, val);
92 mismatch = MISMATCH_DETECTED;
93 }
94
95 /* check CACHE LOCK bit in NS Aux. Config. Register */
96 val = tegra_smmu_read_32(smmu_id, SMMU_GNSR_ACR);
97 if (0U == (val & SMMU_ACR_CACHE_LOCK_ENABLE_BIT)) {
98 ERROR("%s: Mismatch - smmu_id=%d, GNSR_ACR=%x\n",
99 __func__, smmu_id, val);
100 mismatch = MISMATCH_DETECTED;
101 }
102
103 /* verify TCU prefetch for all contexts is disabled */
104 ctx_base = (SMMU_GSR0_PGSIZE_64K * SMMU_NUM_CONTEXTS) +
105 SMMU_CBn_ACTLR;
106 for (cb_idx = 0U; cb_idx < SMMU_CONTEXT_BANK_MAX_IDX; cb_idx++) {
107 val = tegra_smmu_read_32(smmu_id,
108 ctx_base + (SMMU_GSR0_PGSIZE_64K * cb_idx));
109 if (0U != (val & SMMU_CBn_ACTLR_CPRE_BIT)) {
110 ERROR("%s: Mismatch - smmu_id=%d, cb_idx=%d, GSR0_PGSIZE_64K=%x\n",
111 __func__, smmu_id, cb_idx, val);
112 mismatch = MISMATCH_DETECTED;
113 }
114 }
115 }
116
117 /* Treat configuration mismatch as fatal */
118 if ((mismatch == MISMATCH_DETECTED) && tegra_platform_is_silicon()) {
119 panic();
120 }
121}