blob: d6313a68f4dec7cec62e69d663927f40cbed1dc9 [file] [log] [blame]
Soren Brinkmann76fcae32016-03-06 20:16:27 -08001/*
Jolly Shah6a903472019-08-27 11:23:08 -07002 * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved.
Soren Brinkmann76fcae32016-03-06 20:16:27 -08003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soren Brinkmann76fcae32016-03-06 20:16:27 -08005 */
6
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +05307#include <stdbool.h>
8#include <string.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
10#include <common/debug.h>
11#include <drivers/generic_delay_timer.h>
12#include <lib/mmio.h>
13#include <lib/xlat_tables/xlat_tables.h>
Jolly Shah6a903472019-08-27 11:23:08 -070014#include <plat_ipi.h>
Jolly Shah0bfd7002019-01-08 11:10:47 -080015#include <plat_private.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016#include <plat/common/platform.h>
17
Siva Durga Prasad Paladugu00ae6c52017-02-20 17:55:50 +053018#include "pm_api_sys.h"
Soren Brinkmann76fcae32016-03-06 20:16:27 -080019
20/*
21 * Table of regions to map using the MMU.
22 * This doesn't include TZRAM as the 'mem_layout' argument passed to
23 * configure_mmu_elx() will give the available subset of that,
24 */
25const mmap_region_t plat_arm_mmap[] = {
26 { DEVICE0_BASE, DEVICE0_BASE, DEVICE0_SIZE, MT_DEVICE | MT_RW | MT_SECURE },
27 { DEVICE1_BASE, DEVICE1_BASE, DEVICE1_SIZE, MT_DEVICE | MT_RW | MT_SECURE },
28 { CRF_APB_BASE, CRF_APB_BASE, CRF_APB_SIZE, MT_DEVICE | MT_RW | MT_SECURE },
29 {0}
30};
31
32static unsigned int zynqmp_get_silicon_ver(void)
33{
Soren Brinkmann85863992016-09-16 10:34:47 -070034 static unsigned int ver;
Soren Brinkmann76fcae32016-03-06 20:16:27 -080035
Soren Brinkmann85863992016-09-16 10:34:47 -070036 if (!ver) {
37 ver = mmio_read_32(ZYNQMP_CSU_BASEADDR +
38 ZYNQMP_CSU_VERSION_OFFSET);
39 ver &= ZYNQMP_SILICON_VER_MASK;
40 ver >>= ZYNQMP_SILICON_VER_SHIFT;
41 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -080042
43 return ver;
44}
45
46unsigned int zynqmp_get_uart_clk(void)
47{
48 unsigned int ver = zynqmp_get_silicon_ver();
49
Siva Durga Prasad Paladugudff07122018-09-04 18:02:25 +053050 if (ver == ZYNQMP_CSU_VERSION_QEMU)
Soren Brinkmann76fcae32016-03-06 20:16:27 -080051 return 133000000;
Siva Durga Prasad Paladugudff07122018-09-04 18:02:25 +053052 else
53 return 100000000;
Soren Brinkmann76fcae32016-03-06 20:16:27 -080054}
55
Soren Brinkmann76fcae32016-03-06 20:16:27 -080056#if LOG_LEVEL >= LOG_LEVEL_NOTICE
57static const struct {
58 unsigned int id;
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053059 unsigned int ver;
Soren Brinkmann76fcae32016-03-06 20:16:27 -080060 char *name;
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +053061 bool evexists;
Soren Brinkmann76fcae32016-03-06 20:16:27 -080062} zynqmp_devices[] = {
63 {
64 .id = 0x10,
65 .name = "3EG",
66 },
67 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053068 .id = 0x10,
69 .ver = 0x2c,
70 .name = "3CG",
71 },
72 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -080073 .id = 0x11,
74 .name = "2EG",
75 },
76 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053077 .id = 0x11,
78 .ver = 0x2c,
79 .name = "2CG",
80 },
81 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -080082 .id = 0x20,
83 .name = "5EV",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +053084 .evexists = true,
Soren Brinkmann76fcae32016-03-06 20:16:27 -080085 },
86 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053087 .id = 0x20,
88 .ver = 0x100,
89 .name = "5EG",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +053090 .evexists = true,
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053091 },
92 {
93 .id = 0x20,
94 .ver = 0x12c,
95 .name = "5CG",
96 },
97 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -080098 .id = 0x21,
99 .name = "4EV",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530100 .evexists = true,
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800101 },
102 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530103 .id = 0x21,
104 .ver = 0x100,
105 .name = "4EG",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530106 .evexists = true,
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530107 },
108 {
109 .id = 0x21,
110 .ver = 0x12c,
111 .name = "4CG",
112 },
113 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800114 .id = 0x30,
115 .name = "7EV",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530116 .evexists = true,
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800117 },
118 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530119 .id = 0x30,
120 .ver = 0x100,
121 .name = "7EG",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530122 .evexists = true,
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530123 },
124 {
125 .id = 0x30,
126 .ver = 0x12c,
127 .name = "7CG",
128 },
129 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800130 .id = 0x38,
131 .name = "9EG",
132 },
133 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530134 .id = 0x38,
135 .ver = 0x2c,
136 .name = "9CG",
137 },
138 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800139 .id = 0x39,
140 .name = "6EG",
141 },
142 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530143 .id = 0x39,
144 .ver = 0x2c,
145 .name = "6CG",
146 },
147 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800148 .id = 0x40,
149 .name = "11EG",
150 },
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530151 { /* For testing purpose only */
152 .id = 0x50,
153 .ver = 0x2c,
154 .name = "15CG",
155 },
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800156 {
157 .id = 0x50,
158 .name = "15EG",
159 },
160 {
161 .id = 0x58,
162 .name = "19EG",
163 },
164 {
165 .id = 0x59,
166 .name = "17EG",
167 },
Siva Durga Prasad Paladugu19d69c02017-06-06 12:54:52 +0530168 {
169 .id = 0x60,
170 .name = "28DR",
171 },
172 {
173 .id = 0x61,
174 .name = "21DR",
175 },
176 {
177 .id = 0x62,
178 .name = "29DR",
179 },
180 {
181 .id = 0x63,
182 .name = "23DR",
183 },
184 {
185 .id = 0x64,
186 .name = "27DR",
187 },
188 {
189 .id = 0x65,
190 .name = "25DR",
191 },
Siva Durga Prasad Paladugu32267282019-03-23 15:26:31 +0530192 {
193 .id = 0x66,
194 .name = "39DR",
195 },
Venkatesh Yadav Abbarapu927c2b92019-07-30 11:12:55 +0530196 {
197 .id = 0x7b,
198 .name = "48DR",
199 },
200 {
201 .id = 0x7e,
202 .name = "49DR",
203 },
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800204};
205
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530206#define ZYNQMP_PL_STATUS_BIT 9
207#define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT)
208#define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK)
209
210static char *zynqmp_get_silicon_idcode_name(void)
Soren Brinkmanncb366812016-09-22 12:21:11 -0700211{
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530212 uint32_t id, ver, chipid[2];
213 size_t i, j, len;
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530214 const char *name = "EG/EV";
Soren Brinkmanncb366812016-09-22 12:21:11 -0700215
Siva Durga Prasad Paladugu6a8933c2018-06-20 17:03:57 +0530216#ifdef IMAGE_BL32
217 /*
218 * For BL32, get the chip id info directly by reading corresponding
219 * registers instead of making pm call. This has limitation
220 * that these registers should be configured to have access
221 * from APU which is default case.
222 */
223 chipid[0] = mmio_read_32(ZYNQMP_CSU_BASEADDR + ZYNQMP_CSU_IDCODE_OFFSET);
224 chipid[1] = mmio_read_32(EFUSE_BASEADDR + EFUSE_IPDISABLE_OFFSET);
225#else
226 if (pm_get_chipid(chipid) != PM_RET_SUCCESS)
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530227 return "UNKN";
Siva Durga Prasad Paladugu6a8933c2018-06-20 17:03:57 +0530228#endif
Soren Brinkmanncb366812016-09-22 12:21:11 -0700229
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530230 id = chipid[0] & (ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
231 ZYNQMP_CSU_IDCODE_SVD_MASK);
Soren Brinkmanncb366812016-09-22 12:21:11 -0700232 id >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530233 ver = chipid[1] >> ZYNQMP_EFUSE_IPDISABLE_SHIFT;
Soren Brinkmanncb366812016-09-22 12:21:11 -0700234
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530235 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
236 if (zynqmp_devices[i].id == id &&
237 zynqmp_devices[i].ver == (ver & ZYNQMP_CSU_VERSION_MASK))
238 break;
239 }
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530240
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530241 if (i >= ARRAY_SIZE(zynqmp_devices))
242 return "UNKN";
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530243
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530244 if (!zynqmp_devices[i].evexists)
245 return zynqmp_devices[i].name;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800246
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530247 if (ver & ZYNQMP_PL_STATUS_MASK)
248 return zynqmp_devices[i].name;
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530249
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530250 len = strlen(zynqmp_devices[i].name) - 2;
251 for (j = 0; j < strlen(name); j++) {
252 zynqmp_devices[i].name[len] = name[j];
253 len++;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800254 }
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530255 zynqmp_devices[i].name[len] = '\0';
256
257 return zynqmp_devices[i].name;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800258}
259
260static unsigned int zynqmp_get_rtl_ver(void)
261{
262 uint32_t ver;
263
264 ver = mmio_read_32(ZYNQMP_CSU_BASEADDR + ZYNQMP_CSU_VERSION_OFFSET);
265 ver &= ZYNQMP_RTL_VER_MASK;
266 ver >>= ZYNQMP_RTL_VER_SHIFT;
267
268 return ver;
269}
270
271static char *zynqmp_print_silicon_idcode(void)
272{
273 uint32_t id, maskid, tmp;
274
275 id = mmio_read_32(ZYNQMP_CSU_BASEADDR + ZYNQMP_CSU_IDCODE_OFFSET);
276
277 tmp = id;
278 tmp &= ZYNQMP_CSU_IDCODE_XILINX_ID_MASK |
Soren Brinkmann31114132016-05-20 07:05:00 -0700279 ZYNQMP_CSU_IDCODE_FAMILY_MASK;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800280 maskid = ZYNQMP_CSU_IDCODE_XILINX_ID << ZYNQMP_CSU_IDCODE_XILINX_ID_SHIFT |
Soren Brinkmann31114132016-05-20 07:05:00 -0700281 ZYNQMP_CSU_IDCODE_FAMILY << ZYNQMP_CSU_IDCODE_FAMILY_SHIFT;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800282 if (tmp != maskid) {
283 ERROR("Incorrect XILINX IDCODE 0x%x, maskid 0x%x\n", id, maskid);
284 return "UNKN";
285 }
286 VERBOSE("Xilinx IDCODE 0x%x\n", id);
287 return zynqmp_get_silicon_idcode_name();
288}
289
290static unsigned int zynqmp_get_ps_ver(void)
291{
292 uint32_t ver = mmio_read_32(ZYNQMP_CSU_BASEADDR + ZYNQMP_CSU_VERSION_OFFSET);
293
294 ver &= ZYNQMP_PS_VER_MASK;
295 ver >>= ZYNQMP_PS_VER_SHIFT;
296
297 return ver + 1;
298}
299
300static void zynqmp_print_platform_name(void)
301{
302 unsigned int ver = zynqmp_get_silicon_ver();
303 unsigned int rtl = zynqmp_get_rtl_ver();
304 char *label = "Unknown";
305
306 switch (ver) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800307 case ZYNQMP_CSU_VERSION_QEMU:
308 label = "QEMU";
309 break;
310 case ZYNQMP_CSU_VERSION_SILICON:
311 label = "silicon";
312 break;
Jonathan Wrightff957ed2018-03-14 15:24:00 +0000313 default:
314 /* Do nothing in default case */
315 break;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800316 }
317
Siva Durga Prasad Paladugu40808bc2018-04-30 19:43:03 +0530318 NOTICE("ATF running on XCZU%s/%s v%d/RTL%d.%d at 0x%x\n",
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800319 zynqmp_print_silicon_idcode(), label, zynqmp_get_ps_ver(),
Siva Durga Prasad Paladugu40808bc2018-04-30 19:43:03 +0530320 (rtl & 0xf0) >> 4, rtl & 0xf, BL31_BASE);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800321}
322#else
323static inline void zynqmp_print_platform_name(void) { }
324#endif
325
Soren Brinkmannb43d9432016-04-18 11:49:42 -0700326unsigned int zynqmp_get_bootmode(void)
327{
Siva Durga Prasad Paladugu00ae6c52017-02-20 17:55:50 +0530328 uint32_t r;
Siva Durga Prasad Paladugu40808bc2018-04-30 19:43:03 +0530329 unsigned int ret;
Siva Durga Prasad Paladugu00ae6c52017-02-20 17:55:50 +0530330
Siva Durga Prasad Paladugu40808bc2018-04-30 19:43:03 +0530331 ret = pm_mmio_read(CRL_APB_BOOT_MODE_USER, &r);
332
333 if (ret != PM_RET_SUCCESS)
Siva Durga Prasad Paladugu00ae6c52017-02-20 17:55:50 +0530334 r = mmio_read_32(CRL_APB_BOOT_MODE_USER);
Soren Brinkmannb43d9432016-04-18 11:49:42 -0700335
336 return r & CRL_APB_BOOT_MODE_MASK;
337}
338
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800339void zynqmp_config_setup(void)
340{
Jolly Shah6a903472019-08-27 11:23:08 -0700341 /* Configure IPI data for ZynqMP */
342 zynqmp_ipi_config_table_init();
343
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800344 zynqmp_print_platform_name();
Soren Brinkmanne5bdcaa2016-06-22 09:02:56 -0700345 generic_delay_timer_init();
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800346}
347
Antonio Nino Diaze82e29c2016-05-19 10:00:28 +0100348unsigned int plat_get_syscnt_freq2(void)
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800349{
Soren Brinkmanncfcb1a22016-09-16 10:31:06 -0700350 unsigned int ver = zynqmp_get_silicon_ver();
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800351
Siva Durga Prasad Paladugudff07122018-09-04 18:02:25 +0530352 if (ver == ZYNQMP_CSU_VERSION_QEMU)
Edgar E. Iglesias481d2c22019-04-17 15:21:28 +0200353 return 65000000;
Siva Durga Prasad Paladugudff07122018-09-04 18:02:25 +0530354 else
355 return mmio_read_32(IOU_SCNTRS_BASEFREQ);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800356}