blob: a4a4354e8fbf67a58879b537266933a45c216e91 [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 Raithatha75c94432018-08-03 15:48:15 +053021#define SMMU_NUM_CONTEXTS 64U
22#define SMMU_CONTEXT_BANK_MAX_IDX 64U
Varun Wadekarea709c32016-04-20 17:14:15 -070023
Varun Wadekar3c959932016-03-03 13:09:08 -080024/*
25 * Init SMMU during boot or "System Suspend" exit
26 */
27void tegra_smmu_init(void)
28{
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053029 uint32_t val, cb_idx, smmu_id, ctx_base;
Steven Kao7fd30f52017-07-25 11:29:46 +080030 uint32_t smmu_counter = plat_get_num_smmu_devices();
31
Anthony Zhou0e07e452017-07-26 17:16:54 +080032 for (smmu_id = 0U; smmu_id < smmu_counter; smmu_id++) {
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053033 /* Program the SMMU pagesize and reset CACHE_LOCK bit */
34 val = tegra_smmu_read_32(smmu_id, SMMU_GSR0_SECURE_ACR);
35 val |= SMMU_GSR0_PGSIZE_64K;
Anthony Zhou0e07e452017-07-26 17:16:54 +080036 val &= (uint32_t)~SMMU_ACR_CACHE_LOCK_ENABLE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053037 tegra_smmu_write_32(smmu_id, SMMU_GSR0_SECURE_ACR, val);
Varun Wadekarea709c32016-04-20 17:14:15 -070038
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053039 /* reset CACHE LOCK bit for NS Aux. Config. Register */
40 val = tegra_smmu_read_32(smmu_id, SMMU_GNSR_ACR);
Anthony Zhou0e07e452017-07-26 17:16:54 +080041 val &= (uint32_t)~SMMU_ACR_CACHE_LOCK_ENABLE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053042 tegra_smmu_write_32(smmu_id, SMMU_GNSR_ACR, val);
Varun Wadekarea709c32016-04-20 17:14:15 -070043
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053044 /* disable TCU prefetch for all contexts */
45 ctx_base = (SMMU_GSR0_PGSIZE_64K * SMMU_NUM_CONTEXTS)
46 + SMMU_CBn_ACTLR;
47 for (cb_idx = 0; cb_idx < SMMU_CONTEXT_BANK_MAX_IDX; cb_idx++) {
48 val = tegra_smmu_read_32(smmu_id,
49 ctx_base + (SMMU_GSR0_PGSIZE_64K * cb_idx));
Anthony Zhou0e07e452017-07-26 17:16:54 +080050 val &= (uint32_t)~SMMU_CBn_ACTLR_CPRE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053051 tegra_smmu_write_32(smmu_id, ctx_base +
52 (SMMU_GSR0_PGSIZE_64K * cb_idx), val);
53 }
Varun Wadekarea709c32016-04-20 17:14:15 -070054
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053055 /* set CACHE LOCK bit for NS Aux. Config. Register */
56 val = tegra_smmu_read_32(smmu_id, SMMU_GNSR_ACR);
Anthony Zhou0e07e452017-07-26 17:16:54 +080057 val |= (uint32_t)SMMU_ACR_CACHE_LOCK_ENABLE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053058 tegra_smmu_write_32(smmu_id, SMMU_GNSR_ACR, val);
Varun Wadekarea709c32016-04-20 17:14:15 -070059
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053060 /* set CACHE LOCK bit for S Aux. Config. Register */
61 val = tegra_smmu_read_32(smmu_id, SMMU_GSR0_SECURE_ACR);
Anthony Zhou0e07e452017-07-26 17:16:54 +080062 val |= (uint32_t)SMMU_ACR_CACHE_LOCK_ENABLE_BIT;
Pritesh Raithatha0de6e532017-01-24 13:49:46 +053063 tegra_smmu_write_32(smmu_id, SMMU_GSR0_SECURE_ACR, val);
64 }
Varun Wadekar3c959932016-03-03 13:09:08 -080065}