blob: 59d857244af1f8e00805a444cd2392bd2ea1af2a [file] [log] [blame]
tony.xie54973e72017-04-24 16:18:10 +08001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
dp-armd91aaae2017-05-10 15:16:15 +01004 * SPDX-License-Identifier: BSD-3-Clause
tony.xie54973e72017-04-24 16:18:10 +08005 */
6
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <platform_def.h>
8
tony.xie54973e72017-04-24 16:18:10 +08009#include <arch_helpers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <common/debug.h>
11#include <drivers/console.h>
12#include <drivers/delay_timer.h>
13#include <lib/mmio.h>
14
Isla Mitchelle3631462017-07-14 10:46:32 +010015#include <ddr_parameter.h>
tony.xie54973e72017-04-24 16:18:10 +080016#include <plat_private.h>
tony.xie54973e72017-04-24 16:18:10 +080017#include <rk3328_def.h>
18#include <soc.h>
19
20/* Table of regions to map using the MMU. */
21const mmap_region_t plat_rk_mmap[] = {
Christoph Müllner9fecc192019-05-01 01:37:58 +020022 MAP_REGION_FLAT(UART0_BASE, UART0_SIZE,
23 MT_DEVICE | MT_RW | MT_SECURE),
24 MAP_REGION_FLAT(UART1_BASE, UART1_SIZE,
25 MT_DEVICE | MT_RW | MT_SECURE),
tony.xie54973e72017-04-24 16:18:10 +080026 MAP_REGION_FLAT(UART2_BASE, UART2_SIZE,
27 MT_DEVICE | MT_RW | MT_SECURE),
28 MAP_REGION_FLAT(PMU_BASE, PMU_SIZE,
29 MT_DEVICE | MT_RW | MT_SECURE),
30 MAP_REGION_FLAT(SGRF_BASE, SGRF_SIZE,
31 MT_DEVICE | MT_RW | MT_SECURE),
32 MAP_REGION_FLAT(GPIO0_BASE, GPIO0_SIZE,
33 MT_DEVICE | MT_RW | MT_SECURE),
34 MAP_REGION_FLAT(GPIO1_BASE, GPIO1_SIZE,
35 MT_DEVICE | MT_RW | MT_SECURE),
36 MAP_REGION_FLAT(GPIO2_BASE, GPIO2_SIZE,
37 MT_DEVICE | MT_RW | MT_SECURE),
38 MAP_REGION_FLAT(GPIO3_BASE, GPIO3_SIZE,
39 MT_DEVICE | MT_RW | MT_SECURE),
40 MAP_REGION_FLAT(CRU_BASE, CRU_SIZE,
41 MT_DEVICE | MT_RW | MT_SECURE),
42 MAP_REGION_FLAT(GRF_BASE, GRF_SIZE,
43 MT_DEVICE | MT_RW | MT_SECURE),
44 MAP_REGION_FLAT(FIREWALL_DDR_BASE, FIREWALL_DDR_SIZE,
45 MT_DEVICE | MT_RW | MT_SECURE),
46 MAP_REGION_FLAT(FIREWALL_CFG_BASE, FIREWALL_CFG_SIZE,
47 MT_DEVICE | MT_RW | MT_SECURE),
48 MAP_REGION_FLAT(STIME_BASE, STIME_SIZE,
49 MT_DEVICE | MT_RW | MT_SECURE),
50 MAP_REGION_FLAT(GIC400_BASE, GIC400_SIZE,
51 MT_DEVICE | MT_RW | MT_SECURE),
52 MAP_REGION_FLAT(PMUSRAM_BASE, PMUSRAM_SIZE,
53 MT_MEMORY | MT_RW | MT_SECURE),
54 MAP_REGION_FLAT(SHARE_MEM_BASE, SHARE_MEM_SIZE,
55 MT_DEVICE | MT_RW | MT_SECURE),
56 MAP_REGION_FLAT(DDR_GRF_BASE, DDR_GRF_SIZE,
57 MT_DEVICE | MT_RW | MT_SECURE),
58 MAP_REGION_FLAT(DDR_UPCTL_BASE, DDR_UPCTL_SIZE,
59 MT_DEVICE | MT_RW | MT_SECURE),
60 MAP_REGION_FLAT(PWM_BASE, PWM_SIZE,
61 MT_DEVICE | MT_RW | MT_SECURE),
62 MAP_REGION_FLAT(DDR_PARAM_BASE, DDR_PARAM_SIZE,
63 MT_DEVICE | MT_RW | MT_SECURE),
64 MAP_REGION_FLAT(EFUSE8_BASE, EFUSE8_SIZE,
65 MT_DEVICE | MT_RW | MT_SECURE),
66 MAP_REGION_FLAT(EFUSE32_BASE, EFUSE32_SIZE,
67 MT_DEVICE | MT_RW | MT_SECURE),
68 MAP_REGION_FLAT(DDR_PHY_BASE, DDR_PHY_SIZE,
69 MT_DEVICE | MT_RW | MT_SECURE),
70 MAP_REGION_FLAT(SERVER_MSCH_BASE, SERVER_MSCH_SIZE,
71 MT_DEVICE | MT_RW | MT_SECURE),
72 MAP_REGION_FLAT(DDR_MONITOR_BASE, DDR_MONITOR_SIZE,
73 MT_DEVICE | MT_RW | MT_SECURE),
74 MAP_REGION_FLAT(VOP_BASE, VOP_SIZE,
75 MT_DEVICE | MT_RW | MT_SECURE),
76
77 { 0 }
78};
79
80/* The RockChip power domain tree descriptor */
81const unsigned char rockchip_power_domain_tree_desc[] = {
82 /* No of root nodes */
83 PLATFORM_SYSTEM_COUNT,
84 /* No of children for the root node */
85 PLATFORM_CLUSTER_COUNT,
86 /* No of children for the first cluster node */
87 PLATFORM_CLUSTER0_CORE_COUNT,
88};
89
90void secure_timer_init(void)
91{
92 mmio_write_32(STIMER_CHN_BASE(1) + TIMER_LOADE_COUNT0, 0xffffffff);
93 mmio_write_32(STIMER_CHN_BASE(1) + TIMER_LOADE_COUNT1, 0xffffffff);
94 /* auto reload & enable the timer */
95 mmio_write_32(STIMER_CHN_BASE(1) + TIMER_CONTROL_REG, TIMER_EN);
96}
97
98void sgrf_init(void)
99{
100 uint32_t i, val;
101 struct param_ddr_usage usg;
102
103 /* general secure regions */
104 usg = ddr_region_usage_parse(DDR_PARAM_BASE,
105 PLAT_MAX_DDR_CAPACITY_MB);
106 for (i = 0; i < usg.s_nr; i++) {
107 /* enable secure */
108 val = mmio_read_32(FIREWALL_DDR_BASE +
109 FIREWALL_DDR_FW_DDR_CON_REG);
110 val |= BIT(7 - i);
111 mmio_write_32(FIREWALL_DDR_BASE +
112 FIREWALL_DDR_FW_DDR_CON_REG, val);
113 /* map top and base */
114 mmio_write_32(FIREWALL_DDR_BASE +
115 FIREWALL_DDR_FW_DDR_RGN(7 - i),
116 RG_MAP_SECURE(usg.s_top[i], usg.s_base[i]));
117 }
118
119 /* set ddr rgn0_top and rga0_top as 0 */
120 mmio_write_32(FIREWALL_DDR_BASE + FIREWALL_DDR_FW_DDR_RGN(0), 0x0);
121
122 /* set all slave ip into no-secure, except stimer */
123 mmio_write_32(FIREWALL_CFG_BASE + FIREWALL_CFG_FW_SYS_CON(0),
124 SGRF_SLV_S_ALL_NS);
125 mmio_write_32(FIREWALL_CFG_BASE + FIREWALL_CFG_FW_SYS_CON(1),
126 SGRF_SLV_S_ALL_NS);
127 mmio_write_32(FIREWALL_CFG_BASE + FIREWALL_CFG_FW_SYS_CON(2),
128 SGRF_SLV_S_ALL_NS | STIMER_S);
129 mmio_write_32(FIREWALL_CFG_BASE + FIREWALL_CFG_FW_SYS_CON(3),
130 SGRF_SLV_S_ALL_NS);
131
132 /* set all master ip into no-secure */
133 mmio_write_32(SGRF_BASE + SGRF_SOC_CON(2), 0xf0000000);
134 mmio_write_32(SGRF_BASE + SGRF_SOC_CON(3), SGRF_MST_S_ALL_NS);
135 mmio_write_32(SGRF_BASE + SGRF_SOC_CON(4), SGRF_MST_S_ALL_NS);
136
137 /* set DMAC into no-secure */
138 mmio_write_32(SGRF_BASE + SGRF_DMAC_CON(3), DMA_IRQ_BOOT_NS);
139 mmio_write_32(SGRF_BASE + SGRF_DMAC_CON(4), DMA_PERI_CH_NS_15_0);
140 mmio_write_32(SGRF_BASE + SGRF_DMAC_CON(5), DMA_PERI_CH_NS_19_16);
141 mmio_write_32(SGRF_BASE + SGRF_DMAC_CON(5), DMA_MANAGER_BOOT_NS);
142
143 /* soft reset dma before use */
144 mmio_write_32(CRU_BASE + CRU_SOFTRSTS_CON(3), DMA_SOFTRST_REQ);
145 udelay(5);
146 mmio_write_32(CRU_BASE + CRU_SOFTRSTS_CON(3), DMA_SOFTRST_RLS);
147}
148
149void plat_rockchip_soc_init(void)
150{
151 secure_timer_init();
152 sgrf_init();
153
154 NOTICE("BL31:Rockchip release version: v%d.%d\n",
155 MAJOR_VERSION, MINOR_VERSION);
156}