blob: 2f43f0b9c4a09fd3ce3a515ce90b6e9146950866 [file] [log] [blame]
Varun Wadekar96b6cd22020-03-16 17:40:59 -07001/*
2 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
Varun Wadekarfa6a2d22020-03-20 22:41:32 -07008#include <arch_helpers.h>
Varun Wadekar96b6cd22020-03-16 17:40:59 -07009#include <debug.h>
10#include <mmio.h>
11#include <platform.h>
12#include <stddef.h>
13
14#include <utils_def.h>
15
16/*******************************************************************************
Varun Wadekar96b6cd22020-03-16 17:40:59 -070017 * Secure Scratch 73 to save base address of SMMU register context
18 ******************************************************************************/
19#define SCRATCH_SECURE_RSV73_SCRATCH U(0x2ac)
20
21typedef struct mc_regs {
22 uint32_t reg;
23 uint32_t val;
24} mc_regs_t;
25
26#define mc_smmu_bypass_cfg \
27 { \
Varun Wadekarfa6a2d22020-03-20 22:41:32 -070028 .reg = TEGRA194_SMMU0_BASE, \
Varun Wadekar96b6cd22020-03-16 17:40:59 -070029 .val = 0x00000000U, \
30 }
31
32#define START_OF_TABLE \
33 { \
34 .reg = 0xCAFE05C7U, \
35 .val = 0x00000000U, \
36 }
37
38#define END_OF_TABLE \
39 { \
40 .reg = 0xFFFFFFFFU, \
41 .val = 0xFFFFFFFFU, \
42 }
43
44/*******************************************************************************
45 * Array to hold MC context for Tegra194
46 ******************************************************************************/
47static __attribute__((aligned(16))) mc_regs_t tegra194_mc_context[] = {
48 START_OF_TABLE,
49 mc_smmu_bypass_cfg, /* TBU settings */
50 END_OF_TABLE,
51};
52
53void tegra194_pwr_mgmt_setup(void)
54{
Varun Wadekarfa6a2d22020-03-20 22:41:32 -070055 uintptr_t smmu_ctx_base = (uintptr_t)TEGRA194_SMMU_CTX_BASE;
56
Varun Wadekar96b6cd22020-03-16 17:40:59 -070057 /* index of END_OF_TABLE */
58 tegra194_mc_context[0].val = ARRAY_SIZE(tegra194_mc_context) - 1U;
59
Varun Wadekarfa6a2d22020-03-20 22:41:32 -070060 /* prepare dummy context */
61 for (int i = 1; i < ARRAY_SIZE(tegra194_mc_context) - 1U; i++) {
62 tegra194_mc_context[i].val = mmio_read_32(tegra194_mc_context[i].reg);
63 }
64
65 /* save context for the SC7-RF */
66 memcpy((void *)smmu_ctx_base, (void *)tegra194_mc_context,
67 sizeof(tegra194_mc_context));
68 flush_dcache_range(smmu_ctx_base, sizeof(tegra194_mc_context));
69
Varun Wadekar96b6cd22020-03-16 17:40:59 -070070 /* save SMMU context for SC7-RF to restore */
71 mmio_write_32(TEGRA194_SCRATCH_BASE + SCRATCH_SECURE_RSV73_SCRATCH,
Varun Wadekarfa6a2d22020-03-20 22:41:32 -070072 smmu_ctx_base >> 12);
Varun Wadekar96b6cd22020-03-16 17:40:59 -070073}