Varun Wadekar | 96b6cd2 | 2020-03-16 17:40:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020, NVIDIA Corporation. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
Varun Wadekar | fa6a2d2 | 2020-03-20 22:41:32 -0700 | [diff] [blame] | 8 | #include <arch_helpers.h> |
Varun Wadekar | 96b6cd2 | 2020-03-16 17:40:59 -0700 | [diff] [blame] | 9 | #include <debug.h> |
| 10 | #include <mmio.h> |
| 11 | #include <platform.h> |
| 12 | #include <stddef.h> |
| 13 | |
| 14 | #include <utils_def.h> |
| 15 | |
| 16 | /******************************************************************************* |
Varun Wadekar | 96b6cd2 | 2020-03-16 17:40:59 -0700 | [diff] [blame] | 17 | * Secure Scratch 73 to save base address of SMMU register context |
| 18 | ******************************************************************************/ |
| 19 | #define SCRATCH_SECURE_RSV73_SCRATCH U(0x2ac) |
| 20 | |
| 21 | typedef struct mc_regs { |
| 22 | uint32_t reg; |
| 23 | uint32_t val; |
| 24 | } mc_regs_t; |
| 25 | |
| 26 | #define mc_smmu_bypass_cfg \ |
| 27 | { \ |
anzhou | 113d2d2 | 2020-06-04 13:20:18 +0800 | [diff] [blame^] | 28 | .reg = TEGRA_SMMU0_BASE, \ |
Varun Wadekar | 96b6cd2 | 2020-03-16 17:40:59 -0700 | [diff] [blame] | 29 | .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 | ******************************************************************************/ |
| 47 | static __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 | |
anzhou | 113d2d2 | 2020-06-04 13:20:18 +0800 | [diff] [blame^] | 53 | void tegra_pwr_mgmt_setup(void) |
Varun Wadekar | 96b6cd2 | 2020-03-16 17:40:59 -0700 | [diff] [blame] | 54 | { |
anzhou | 113d2d2 | 2020-06-04 13:20:18 +0800 | [diff] [blame^] | 55 | uintptr_t smmu_ctx_base = (uintptr_t)TEGRA_SMMU_CTX_BASE; |
Varun Wadekar | fa6a2d2 | 2020-03-20 22:41:32 -0700 | [diff] [blame] | 56 | |
Varun Wadekar | 96b6cd2 | 2020-03-16 17:40:59 -0700 | [diff] [blame] | 57 | /* index of END_OF_TABLE */ |
| 58 | tegra194_mc_context[0].val = ARRAY_SIZE(tegra194_mc_context) - 1U; |
| 59 | |
Varun Wadekar | fa6a2d2 | 2020-03-20 22:41:32 -0700 | [diff] [blame] | 60 | /* prepare dummy context */ |
anzhou | 113d2d2 | 2020-06-04 13:20:18 +0800 | [diff] [blame^] | 61 | for (unsigned int i = 1U; i < ARRAY_SIZE(tegra194_mc_context) - 1U; i++) { |
Varun Wadekar | fa6a2d2 | 2020-03-20 22:41:32 -0700 | [diff] [blame] | 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 Wadekar | 96b6cd2 | 2020-03-16 17:40:59 -0700 | [diff] [blame] | 70 | /* save SMMU context for SC7-RF to restore */ |
anzhou | 113d2d2 | 2020-06-04 13:20:18 +0800 | [diff] [blame^] | 71 | mmio_write_32(TEGRA_SCRATCH_BASE + SCRATCH_SECURE_RSV73_SCRATCH, |
Varun Wadekar | fa6a2d2 | 2020-03-20 22:41:32 -0700 | [diff] [blame] | 72 | smmu_ctx_base >> 12); |
Varun Wadekar | 96b6cd2 | 2020-03-16 17:40:59 -0700 | [diff] [blame] | 73 | } |