blob: dba1734c0f2c87e80f9e40e5c77dda251684f0c4 [file] [log] [blame]
Soren Brinkmann76fcae32016-03-06 20:16:27 -08001/*
Michal Simek2a47faa2023-04-14 08:43:51 +02002 * Copyright (c) 2013-2022, Arm Limited and Contributors. All rights reserved.
Jay Buddhabhatti26e138a2022-12-21 23:03:35 -08003 * Copyright (c) 2022-2023, Advanced Micro Devices, Inc. All rights reserved.
Soren Brinkmann76fcae32016-03-06 20:16:27 -08004 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Soren Brinkmann76fcae32016-03-06 20:16:27 -08006 */
7
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +05308#include <stdbool.h>
9#include <string.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <common/debug.h>
12#include <drivers/generic_delay_timer.h>
13#include <lib/mmio.h>
Michal Simekc98da1c2023-02-09 10:28:58 +010014#include <lib/smccc.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <lib/xlat_tables/xlat_tables.h>
Prasad Kummari536e1102023-06-22 10:50:02 +053016#include <plat/common/platform.h>
17#include <services/arm_arch_svc.h>
18
Jolly Shah6a903472019-08-27 11:23:08 -070019#include <plat_ipi.h>
Jolly Shah0bfd7002019-01-08 11:10:47 -080020#include <plat_private.h>
Michal Simekc98da1c2023-02-09 10:28:58 +010021#include <plat_startup.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000022
Jay Buddhabhatti26e138a2022-12-21 23:03:35 -080023#include "zynqmp_pm_api_sys.h"
Soren Brinkmann76fcae32016-03-06 20:16:27 -080024
25/*
26 * Table of regions to map using the MMU.
27 * This doesn't include TZRAM as the 'mem_layout' argument passed to
28 * configure_mmu_elx() will give the available subset of that,
29 */
Prasad Kummari0b377142023-10-26 16:32:26 +053030const mmap_region_t plat_zynqmp_mmap[] = {
Soren Brinkmann76fcae32016-03-06 20:16:27 -080031 { DEVICE0_BASE, DEVICE0_BASE, DEVICE0_SIZE, MT_DEVICE | MT_RW | MT_SECURE },
32 { DEVICE1_BASE, DEVICE1_BASE, DEVICE1_SIZE, MT_DEVICE | MT_RW | MT_SECURE },
33 { CRF_APB_BASE, CRF_APB_BASE, CRF_APB_SIZE, MT_DEVICE | MT_RW | MT_SECURE },
34 {0}
35};
36
Prasad Kummari0b377142023-10-26 16:32:26 +053037const mmap_region_t *plat_get_mmap(void)
38{
39 return plat_zynqmp_mmap;
40}
41
Venkatesh Yadav Abbarapue7c45382022-05-19 14:49:49 +053042static uint32_t zynqmp_get_silicon_ver(void)
Soren Brinkmann76fcae32016-03-06 20:16:27 -080043{
Soren Brinkmann85863992016-09-16 10:34:47 -070044 static unsigned int ver;
Soren Brinkmann76fcae32016-03-06 20:16:27 -080045
Soren Brinkmann85863992016-09-16 10:34:47 -070046 if (!ver) {
47 ver = mmio_read_32(ZYNQMP_CSU_BASEADDR +
48 ZYNQMP_CSU_VERSION_OFFSET);
49 ver &= ZYNQMP_SILICON_VER_MASK;
50 ver >>= ZYNQMP_SILICON_VER_SHIFT;
51 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -080052
53 return ver;
54}
55
Michal Simekc56e5482023-09-27 13:58:06 +020056uint32_t get_uart_clk(void)
Soren Brinkmann76fcae32016-03-06 20:16:27 -080057{
58 unsigned int ver = zynqmp_get_silicon_ver();
59
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +053060 if (ver == ZYNQMP_CSU_VERSION_QEMU) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -080061 return 133000000;
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +053062 } else {
Siva Durga Prasad Paladugudff07122018-09-04 18:02:25 +053063 return 100000000;
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +053064 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -080065}
66
Soren Brinkmann76fcae32016-03-06 20:16:27 -080067#if LOG_LEVEL >= LOG_LEVEL_NOTICE
68static const struct {
Michal Simek918a0dd2023-04-27 14:54:45 +020069 uint8_t id;
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +053070 bool evexists;
Michal Simek918a0dd2023-04-27 14:54:45 +020071 uint16_t ver;
72 char *name;
73} __packed zynqmp_devices[] = {
Soren Brinkmann76fcae32016-03-06 20:16:27 -080074 {
75 .id = 0x10,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -060076 .name = "XCZU3EG",
Soren Brinkmann76fcae32016-03-06 20:16:27 -080077 },
78 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053079 .id = 0x10,
80 .ver = 0x2c,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -060081 .name = "XCZU3CG",
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053082 },
83 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -080084 .id = 0x11,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -060085 .name = "XCZU2EG",
Soren Brinkmann76fcae32016-03-06 20:16:27 -080086 },
87 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053088 .id = 0x11,
89 .ver = 0x2c,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -060090 .name = "XCZU2CG",
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053091 },
92 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -080093 .id = 0x20,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -060094 .name = "XCZU5EV",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +053095 .evexists = true,
Soren Brinkmann76fcae32016-03-06 20:16:27 -080096 },
97 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053098 .id = 0x20,
99 .ver = 0x100,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600100 .name = "XCZU5EG",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530101 .evexists = true,
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530102 },
103 {
104 .id = 0x20,
105 .ver = 0x12c,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600106 .name = "XCZU5CG",
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530107 },
108 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800109 .id = 0x21,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600110 .name = "XCZU4EV",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530111 .evexists = true,
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800112 },
113 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530114 .id = 0x21,
115 .ver = 0x100,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600116 .name = "XCZU4EG",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530117 .evexists = true,
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530118 },
119 {
120 .id = 0x21,
121 .ver = 0x12c,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600122 .name = "XCZU4CG",
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530123 },
124 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800125 .id = 0x30,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600126 .name = "XCZU7EV",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530127 .evexists = true,
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800128 },
129 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530130 .id = 0x30,
131 .ver = 0x100,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600132 .name = "XCZU7EG",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530133 .evexists = true,
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530134 },
135 {
136 .id = 0x30,
137 .ver = 0x12c,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600138 .name = "XCZU7CG",
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530139 },
140 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800141 .id = 0x38,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600142 .name = "XCZU9EG",
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800143 },
144 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530145 .id = 0x38,
146 .ver = 0x2c,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600147 .name = "XCZU9CG",
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530148 },
149 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800150 .id = 0x39,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600151 .name = "XCZU6EG",
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800152 },
153 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530154 .id = 0x39,
155 .ver = 0x2c,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600156 .name = "XCZU6CG",
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530157 },
158 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800159 .id = 0x40,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600160 .name = "XCZU11EG",
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800161 },
162 {
163 .id = 0x50,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600164 .name = "XCZU15EG",
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800165 },
166 {
167 .id = 0x58,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600168 .name = "XCZU19EG",
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800169 },
170 {
171 .id = 0x59,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600172 .name = "XCZU17EG",
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800173 },
Siva Durga Prasad Paladugu19d69c02017-06-06 12:54:52 +0530174 {
175 .id = 0x60,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600176 .name = "XCZU28DR",
Siva Durga Prasad Paladugu19d69c02017-06-06 12:54:52 +0530177 },
178 {
179 .id = 0x61,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600180 .name = "XCZU21DR",
Siva Durga Prasad Paladugu19d69c02017-06-06 12:54:52 +0530181 },
182 {
183 .id = 0x62,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600184 .name = "XCZU29DR",
Siva Durga Prasad Paladugu19d69c02017-06-06 12:54:52 +0530185 },
186 {
187 .id = 0x63,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600188 .name = "XCZU23DR",
Siva Durga Prasad Paladugu19d69c02017-06-06 12:54:52 +0530189 },
190 {
191 .id = 0x64,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600192 .name = "XCZU27DR",
Siva Durga Prasad Paladugu19d69c02017-06-06 12:54:52 +0530193 },
194 {
195 .id = 0x65,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600196 .name = "XCZU25DR",
Siva Durga Prasad Paladugu19d69c02017-06-06 12:54:52 +0530197 },
Siva Durga Prasad Paladugu32267282019-03-23 15:26:31 +0530198 {
199 .id = 0x66,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600200 .name = "XCZU39DR",
Siva Durga Prasad Paladugu32267282019-03-23 15:26:31 +0530201 },
Venkatesh Yadav Abbarapu927c2b92019-07-30 11:12:55 +0530202 {
Venkatesh Yadav Abbarapu5a3226c2021-03-03 00:43:16 -0700203 .id = 0x7d,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600204 .name = "XCZU43DR",
Venkatesh Yadav Abbarapu5a3226c2021-03-03 00:43:16 -0700205 },
206 {
207 .id = 0x78,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600208 .name = "XCZU46DR",
Venkatesh Yadav Abbarapu5a3226c2021-03-03 00:43:16 -0700209 },
210 {
211 .id = 0x7f,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600212 .name = "XCZU47DR",
Venkatesh Yadav Abbarapu5a3226c2021-03-03 00:43:16 -0700213 },
214 {
Venkatesh Yadav Abbarapu927c2b92019-07-30 11:12:55 +0530215 .id = 0x7b,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600216 .name = "XCZU48DR",
Venkatesh Yadav Abbarapu927c2b92019-07-30 11:12:55 +0530217 },
218 {
219 .id = 0x7e,
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600220 .name = "XCZU49DR",
Venkatesh Yadav Abbarapu927c2b92019-07-30 11:12:55 +0530221 },
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800222};
223
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530224#define ZYNQMP_PL_STATUS_BIT 9
225#define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT)
226#define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK)
227
Michal Simekdfe452d2023-01-18 08:55:20 +0100228#define SILICON_ID_XCK24 0x4712093U
Venkatesh Yadav Abbarapua2ca35d2022-07-04 11:40:27 +0530229#define SILICON_ID_XCK26 0x4724093U
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600230
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530231static char *zynqmp_get_silicon_idcode_name(void)
Soren Brinkmanncb366812016-09-22 12:21:11 -0700232{
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530233 uint32_t id, ver, chipid[2];
234 size_t i, j, len;
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530235 const char *name = "EG/EV";
Soren Brinkmanncb366812016-09-22 12:21:11 -0700236
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530237 if (pm_get_chipid(chipid) != PM_RET_SUCCESS) {
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600238 return "XCZUUNKN";
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530239 }
Soren Brinkmanncb366812016-09-22 12:21:11 -0700240
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530241 id = chipid[0] & (ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
242 ZYNQMP_CSU_IDCODE_SVD_MASK);
Soren Brinkmanncb366812016-09-22 12:21:11 -0700243 id >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530244 ver = chipid[1] >> ZYNQMP_EFUSE_IPDISABLE_SHIFT;
Soren Brinkmanncb366812016-09-22 12:21:11 -0700245
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530246 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
247 if (zynqmp_devices[i].id == id &&
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530248 zynqmp_devices[i].ver == (ver & ZYNQMP_CSU_VERSION_MASK)) {
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530249 break;
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530250 }
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530251 }
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530252
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600253 if (i >= ARRAY_SIZE(zynqmp_devices)) {
Venkatesh Yadav Abbarapue88671e2022-05-17 09:39:30 +0530254 switch (chipid[0]) {
255 case SILICON_ID_XCK24:
256 return "XCK24";
257 case SILICON_ID_XCK26:
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600258 return "XCK26";
Venkatesh Yadav Abbarapue88671e2022-05-17 09:39:30 +0530259 default:
Venkatesh Yadav Abbarapufcfdaf02021-04-21 21:54:48 -0600260 return "XCZUUNKN";
261 }
262 }
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530263
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530264 if (!zynqmp_devices[i].evexists) {
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530265 return zynqmp_devices[i].name;
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530266 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800267
Venkatesh Yadav Abbarapu3a33f932022-05-04 14:27:56 +0530268 if ((ver & ZYNQMP_PL_STATUS_MASK) != 0U) {
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530269 return zynqmp_devices[i].name;
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530270 }
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530271
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530272 len = strlen(zynqmp_devices[i].name) - 2;
273 for (j = 0; j < strlen(name); j++) {
274 zynqmp_devices[i].name[len] = name[j];
275 len++;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800276 }
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530277 zynqmp_devices[i].name[len] = '\0';
278
279 return zynqmp_devices[i].name;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800280}
281
282static unsigned int zynqmp_get_rtl_ver(void)
283{
284 uint32_t ver;
285
286 ver = mmio_read_32(ZYNQMP_CSU_BASEADDR + ZYNQMP_CSU_VERSION_OFFSET);
287 ver &= ZYNQMP_RTL_VER_MASK;
288 ver >>= ZYNQMP_RTL_VER_SHIFT;
289
290 return ver;
291}
292
293static char *zynqmp_print_silicon_idcode(void)
294{
295 uint32_t id, maskid, tmp;
296
297 id = mmio_read_32(ZYNQMP_CSU_BASEADDR + ZYNQMP_CSU_IDCODE_OFFSET);
298
299 tmp = id;
300 tmp &= ZYNQMP_CSU_IDCODE_XILINX_ID_MASK |
Soren Brinkmann31114132016-05-20 07:05:00 -0700301 ZYNQMP_CSU_IDCODE_FAMILY_MASK;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800302 maskid = ZYNQMP_CSU_IDCODE_XILINX_ID << ZYNQMP_CSU_IDCODE_XILINX_ID_SHIFT |
Soren Brinkmann31114132016-05-20 07:05:00 -0700303 ZYNQMP_CSU_IDCODE_FAMILY << ZYNQMP_CSU_IDCODE_FAMILY_SHIFT;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800304 if (tmp != maskid) {
Akshay Belsarebdffd362023-01-18 17:04:22 +0530305 ERROR("Incorrect IDCODE 0x%x, maskid 0x%x\n", id, maskid);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800306 return "UNKN";
307 }
Akshay Belsarebdffd362023-01-18 17:04:22 +0530308 VERBOSE("IDCODE 0x%x\n", id);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800309 return zynqmp_get_silicon_idcode_name();
310}
311
Michal Simekc98da1c2023-02-09 10:28:58 +0100312int32_t plat_is_smccc_feature_available(u_register_t fid)
313{
314 switch (fid) {
315 case SMCCC_ARCH_SOC_ID:
316 return SMC_ARCH_CALL_SUCCESS;
317 default:
318 return SMC_ARCH_CALL_NOT_SUPPORTED;
319 }
320
321 return SMC_ARCH_CALL_NOT_SUPPORTED;
322}
323
324int32_t plat_get_soc_version(void)
325{
326 uint32_t chip_id = zynqmp_get_silicon_ver();
327 uint32_t manfid = SOC_ID_SET_JEP_106(JEDEC_XILINX_BKID, JEDEC_XILINX_MFID);
328
329 return (int32_t)(manfid | (chip_id & 0xFFFF));
330}
331
332int32_t plat_get_soc_revision(void)
333{
334 return mmio_read_32(ZYNQMP_CSU_BASEADDR + ZYNQMP_CSU_IDCODE_OFFSET);
335}
336
Venkatesh Yadav Abbarapue7c45382022-05-19 14:49:49 +0530337static uint32_t zynqmp_get_ps_ver(void)
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800338{
339 uint32_t ver = mmio_read_32(ZYNQMP_CSU_BASEADDR + ZYNQMP_CSU_VERSION_OFFSET);
340
341 ver &= ZYNQMP_PS_VER_MASK;
342 ver >>= ZYNQMP_PS_VER_SHIFT;
343
Venkatesh Yadav Abbarapua2ca35d2022-07-04 11:40:27 +0530344 return ver + 1U;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800345}
346
347static void zynqmp_print_platform_name(void)
348{
Venkatesh Yadav Abbarapue7c45382022-05-19 14:49:49 +0530349 uint32_t ver = zynqmp_get_silicon_ver();
350 uint32_t rtl = zynqmp_get_rtl_ver();
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800351 char *label = "Unknown";
352
353 switch (ver) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800354 case ZYNQMP_CSU_VERSION_QEMU:
355 label = "QEMU";
356 break;
357 case ZYNQMP_CSU_VERSION_SILICON:
358 label = "silicon";
359 break;
Jonathan Wrightff957ed2018-03-14 15:24:00 +0000360 default:
361 /* Do nothing in default case */
362 break;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800363 }
364
Venkatesh Yadav Abbarapu50dbb082022-04-12 09:21:32 +0530365 VERBOSE("TF-A running on %s/%s at 0x%x\n",
366 zynqmp_print_silicon_idcode(), label, BL31_BASE);
Venkatesh Yadav Abbarapud4740e42021-06-17 00:23:52 -0600367 VERBOSE("TF-A running on v%d/RTL%d.%d\n",
368 zynqmp_get_ps_ver(), (rtl & 0xf0) >> 4, rtl & 0xf);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800369}
370#else
371static inline void zynqmp_print_platform_name(void) { }
372#endif
373
Venkatesh Yadav Abbarapue7c45382022-05-19 14:49:49 +0530374uint32_t zynqmp_get_bootmode(void)
Soren Brinkmannb43d9432016-04-18 11:49:42 -0700375{
Siva Durga Prasad Paladugu00ae6c52017-02-20 17:55:50 +0530376 uint32_t r;
Siva Durga Prasad Paladugu40808bc2018-04-30 19:43:03 +0530377 unsigned int ret;
Siva Durga Prasad Paladugu00ae6c52017-02-20 17:55:50 +0530378
Siva Durga Prasad Paladugu40808bc2018-04-30 19:43:03 +0530379 ret = pm_mmio_read(CRL_APB_BOOT_MODE_USER, &r);
380
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530381 if (ret != PM_RET_SUCCESS) {
Siva Durga Prasad Paladugu00ae6c52017-02-20 17:55:50 +0530382 r = mmio_read_32(CRL_APB_BOOT_MODE_USER);
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530383 }
Soren Brinkmannb43d9432016-04-18 11:49:42 -0700384
385 return r & CRL_APB_BOOT_MODE_MASK;
386}
387
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800388void zynqmp_config_setup(void)
389{
Rajan Vaja12be18b2021-03-26 04:16:36 -0700390 uint64_t counter_freq;
391
Jolly Shah6a903472019-08-27 11:23:08 -0700392 /* Configure IPI data for ZynqMP */
393 zynqmp_ipi_config_table_init();
394
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800395 zynqmp_print_platform_name();
Rajan Vaja12be18b2021-03-26 04:16:36 -0700396
397 /* Configure counter frequency */
398 counter_freq = read_cntfrq_el0();
399 if (counter_freq == ZYNQMP_DEFAULT_COUNTER_FREQ) {
400 write_cntfrq_el0(plat_get_syscnt_freq2());
401 }
402
Soren Brinkmanne5bdcaa2016-06-22 09:02:56 -0700403 generic_delay_timer_init();
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800404}
405
Venkatesh Yadav Abbarapue7c45382022-05-19 14:49:49 +0530406uint32_t plat_get_syscnt_freq2(void)
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800407{
Venkatesh Yadav Abbarapue7c45382022-05-19 14:49:49 +0530408 uint32_t ver = zynqmp_get_silicon_ver();
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800409
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530410 if (ver == ZYNQMP_CSU_VERSION_QEMU) {
Edgar E. Iglesias481d2c22019-04-17 15:21:28 +0200411 return 65000000;
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530412 } else {
Siva Durga Prasad Paladugudff07122018-09-04 18:02:25 +0530413 return mmio_read_32(IOU_SCNTRS_BASEFREQ);
Venkatesh Yadav Abbarapu987fad32022-04-29 13:52:00 +0530414 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800415}