blob: cc07d654944960d94793a880cc0362c176db3e6a [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 Wadekar93bed2a2016-03-18 13:07:33 -070017#include <tegra_private.h>
Varun Wadekar3c959932016-03-03 13:09:08 -080018
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +010019extern void memcpy16(void *dest, const void *src, unsigned int length);
20
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053021/* SMMU IDs currently supported by the driver */
22enum {
Anthony Zhou0e07e452017-07-26 17:16:54 +080023 TEGRA_SMMU0 = 0U,
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053024 TEGRA_SMMU1,
25 TEGRA_SMMU2
26};
27
28static uint32_t tegra_smmu_read_32(uint32_t smmu_id, uint32_t off)
29{
Anthony Zhou0844b972017-06-28 16:35:54 +080030 uint32_t ret = 0U;
31
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053032#if defined(TEGRA_SMMU0_BASE)
Anthony Zhou0844b972017-06-28 16:35:54 +080033 if (smmu_id == TEGRA_SMMU0) {
34 ret = mmio_read_32(TEGRA_SMMU0_BASE + (uint64_t)off);
35 }
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053036#endif
37
38#if defined(TEGRA_SMMU1_BASE)
Anthony Zhou0844b972017-06-28 16:35:54 +080039 if (smmu_id == TEGRA_SMMU1) {
40 ret = mmio_read_32(TEGRA_SMMU1_BASE + (uint64_t)off);
41 }
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053042#endif
43
44#if defined(TEGRA_SMMU2_BASE)
Anthony Zhou0844b972017-06-28 16:35:54 +080045 if (smmu_id == TEGRA_SMMU2) {
46 ret = mmio_read_32(TEGRA_SMMU2_BASE + (uint64_t)off);
47 }
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053048#endif
49
Anthony Zhou0844b972017-06-28 16:35:54 +080050 return ret;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053051}
52
53static void tegra_smmu_write_32(uint32_t smmu_id,
54 uint32_t off, uint32_t val)
55{
56#if defined(TEGRA_SMMU0_BASE)
Anthony Zhou0844b972017-06-28 16:35:54 +080057 if (smmu_id == TEGRA_SMMU0) {
58 mmio_write_32(TEGRA_SMMU0_BASE + (uint64_t)off, val);
59 }
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053060#endif
61
62#if defined(TEGRA_SMMU1_BASE)
Anthony Zhou0844b972017-06-28 16:35:54 +080063 if (smmu_id == TEGRA_SMMU1) {
64 mmio_write_32(TEGRA_SMMU1_BASE + (uint64_t)off, val);
65 }
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053066#endif
67
68#if defined(TEGRA_SMMU2_BASE)
Anthony Zhou0844b972017-06-28 16:35:54 +080069 if (smmu_id == TEGRA_SMMU2) {
70 mmio_write_32(TEGRA_SMMU2_BASE + (uint64_t)off, val);
71 }
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053072#endif
73}
74
Pritesh Raithatha75c94432018-08-03 15:48:15 +053075#define SMMU_NUM_CONTEXTS 64U
76#define SMMU_CONTEXT_BANK_MAX_IDX 64U
Varun Wadekarea709c32016-04-20 17:14:15 -070077
Varun Wadekar3c959932016-03-03 13:09:08 -080078/*
79 * Init SMMU during boot or "System Suspend" exit
80 */
81void tegra_smmu_init(void)
82{
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053083 uint32_t val, cb_idx, smmu_id, ctx_base;
Steven Kao7fd30f52017-07-25 11:29:46 +080084 uint32_t smmu_counter = plat_get_num_smmu_devices();
85
Anthony Zhou0e07e452017-07-26 17:16:54 +080086 for (smmu_id = 0U; smmu_id < smmu_counter; smmu_id++) {
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053087 /* Program the SMMU pagesize and reset CACHE_LOCK bit */
88 val = tegra_smmu_read_32(smmu_id, SMMU_GSR0_SECURE_ACR);
89 val |= SMMU_GSR0_PGSIZE_64K;
Anthony Zhou0e07e452017-07-26 17:16:54 +080090 val &= (uint32_t)~SMMU_ACR_CACHE_LOCK_ENABLE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053091 tegra_smmu_write_32(smmu_id, SMMU_GSR0_SECURE_ACR, val);
Varun Wadekarea709c32016-04-20 17:14:15 -070092
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053093 /* reset CACHE LOCK bit for NS Aux. Config. Register */
94 val = tegra_smmu_read_32(smmu_id, SMMU_GNSR_ACR);
Anthony Zhou0e07e452017-07-26 17:16:54 +080095 val &= (uint32_t)~SMMU_ACR_CACHE_LOCK_ENABLE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053096 tegra_smmu_write_32(smmu_id, SMMU_GNSR_ACR, val);
Varun Wadekarea709c32016-04-20 17:14:15 -070097
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053098 /* disable TCU prefetch for all contexts */
99 ctx_base = (SMMU_GSR0_PGSIZE_64K * SMMU_NUM_CONTEXTS)
100 + SMMU_CBn_ACTLR;
101 for (cb_idx = 0; cb_idx < SMMU_CONTEXT_BANK_MAX_IDX; cb_idx++) {
102 val = tegra_smmu_read_32(smmu_id,
103 ctx_base + (SMMU_GSR0_PGSIZE_64K * cb_idx));
Anthony Zhou0e07e452017-07-26 17:16:54 +0800104 val &= (uint32_t)~SMMU_CBn_ACTLR_CPRE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +0530105 tegra_smmu_write_32(smmu_id, ctx_base +
106 (SMMU_GSR0_PGSIZE_64K * cb_idx), val);
107 }
Varun Wadekarea709c32016-04-20 17:14:15 -0700108
Pritesh Raithatha0de6e532017-01-24 13:49:46 +0530109 /* set CACHE LOCK bit for NS Aux. Config. Register */
110 val = tegra_smmu_read_32(smmu_id, SMMU_GNSR_ACR);
Anthony Zhou0e07e452017-07-26 17:16:54 +0800111 val |= (uint32_t)SMMU_ACR_CACHE_LOCK_ENABLE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +0530112 tegra_smmu_write_32(smmu_id, SMMU_GNSR_ACR, val);
Varun Wadekarea709c32016-04-20 17:14:15 -0700113
Pritesh Raithatha0de6e532017-01-24 13:49:46 +0530114 /* set CACHE LOCK bit for S Aux. Config. Register */
115 val = tegra_smmu_read_32(smmu_id, SMMU_GSR0_SECURE_ACR);
Anthony Zhou0e07e452017-07-26 17:16:54 +0800116 val |= (uint32_t)SMMU_ACR_CACHE_LOCK_ENABLE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +0530117 tegra_smmu_write_32(smmu_id, SMMU_GSR0_SECURE_ACR, val);
118 }
Varun Wadekar3c959932016-03-03 13:09:08 -0800119}