xref: /rk3399_ARM-atf/plat/xilinx/versal/aarch64/versal_common.c (revision 5e0be8c0241e5075b34bd5b14df2df9f048715d3)
1 /*
2  * Copyright (c) 2018-2020, Arm Limited and Contributors. All rights reserved.
3  * Copyright (c) 2022-2024, Advanced Micro Devices, Inc. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include <common/debug.h>
9 #include <lib/mmio.h>
10 #include <lib/xlat_tables/xlat_tables_v2.h>
11 #include <plat/common/platform.h>
12 
13 #include <plat_common.h>
14 #include <plat_ipi.h>
15 #include <plat_private.h>
16 #include <pm_api_sys.h>
17 #include <versal_def.h>
18 
19 uint32_t platform_id, platform_version;
20 uint32_t cpu_clock;
21 
22 /*
23  * Table of regions to map using the MMU.
24  * This doesn't include TZRAM as the 'mem_layout' argument passed to
25  * configure_mmu_elx() will give the available subset of that,
26  */
27 const mmap_region_t plat_versal_mmap[] = {
28 	MAP_REGION_FLAT(DEVICE0_BASE, DEVICE0_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
29 	MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
30 	MAP_REGION_FLAT(CRF_BASE, CRF_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
31 	MAP_REGION_FLAT(PLAT_ARM_CCI_BASE, PLAT_ARM_CCI_SIZE, MT_DEVICE | MT_RW |
32 			MT_SECURE),
33 	{ 0 }
34 };
35 
36 const mmap_region_t *plat_get_mmap(void)
37 {
38 	return plat_versal_mmap;
39 }
40 
41 void versal_config_setup(void)
42 {
43 	/* Configure IPI data for versal */
44 	versal_ipi_config_table_init();
45 }
46 
47 void board_detection(void)
48 {
49 	uint32_t plat_info[2];
50 
51 	if (pm_get_chipid(plat_info) != PM_RET_SUCCESS) {
52 		/* If the call is failed we cannot proceed with further
53 		 * setup. TF-A to panic in this situation.
54 		 */
55 		NOTICE("Failed to read the chip information");
56 		panic();
57 	}
58 
59 	platform_id = FIELD_GET(PLATFORM_MASK, plat_info[1]);
60 	platform_version = FIELD_GET(PLATFORM_VERSION_MASK, plat_info[1]);
61 }
62 
63 const char *board_name_decode(void)
64 {
65 	const char *platform;
66 
67 	switch (platform_id) {
68 	case VERSAL_SPP:
69 		platform = "IPP";
70 		break;
71 	case VERSAL_EMU:
72 		platform = "EMU";
73 		break;
74 	case VERSAL_QEMU:
75 		platform = "QEMU";
76 		break;
77 	case VERSAL_SILICON:
78 		platform = "SILICON";
79 		break;
80 	default:
81 		platform = "unknown";
82 	}
83 
84 	return platform;
85 }
86 
87 uint32_t get_uart_clk(void)
88 {
89 	uint32_t uart_clock;
90 
91 	switch (platform_id) {
92 	case VERSAL_SPP:
93 		uart_clock = 25000000;
94 		break;
95 	case VERSAL_EMU:
96 		uart_clock = 212000;
97 		break;
98 	case VERSAL_QEMU:
99 		uart_clock = 25000000;
100 		break;
101 	case VERSAL_SILICON:
102 		uart_clock = 100000000;
103 		break;
104 	default:
105 		panic();
106 	}
107 
108 	return uart_clock;
109 }
110