blob: ef58384570f1f3a64ff89719558be674e862109f [file] [log] [blame]
Soby Mathewb4c6df42022-11-09 11:13:29 +00001/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4 */
AlexeiFedorov7c5001a2022-12-14 13:22:33 +00005
Javier Almansa Sobrinof6fff692024-02-02 17:13:57 +00006#include <arch_features.h>
Soby Mathew9b2de242024-02-27 16:08:42 +00007#include <arm_dram.h>
Soby Mathewb4c6df42022-11-09 11:13:29 +00008#include <debug.h>
Soby Mathewb4c6df42022-11-09 11:13:29 +00009#include <pl011.h>
10#include <plat_common.h>
AlexeiFedorovee2fc822023-10-31 14:54:39 +000011#include <platform_api.h>
AlexeiFedorov7c5001a2022-12-14 13:22:33 +000012#include <rmm_el3_ifc.h>
Soby Mathewb4c6df42022-11-09 11:13:29 +000013#include <sizes.h>
Soby Mathew9dcdb152024-02-27 15:15:28 +000014#include <string.h>
Soby Mathewb4c6df42022-11-09 11:13:29 +000015#include <xlat_tables.h>
16
Soby Mathew9b2de242024-02-27 16:08:42 +000017#define ARM_RMM_UART MAP_REGION_FLAT( \
Soby Mathew9dcdb152024-02-27 15:15:28 +000018 0, \
Soby Mathew8218e082024-02-26 14:09:28 +000019 SZ_4K, \
20 (MT_DEVICE | MT_RW | MT_REALM))
Soby Mathewb4c6df42022-11-09 11:13:29 +000021
Soby Mathewb4c6df42022-11-09 11:13:29 +000022/*
23 * Local platform setup for RMM.
24 *
25 * This function will only be invoked during
26 * warm boot and is expected to setup architecture and platform
27 * components local to a PE executing RMM.
28 */
AlexeiFedorovb0de4d52023-10-10 11:46:16 +010029/* coverity[misra_c_2012_rule_8_7_violation:SUPPRESS] */
Soby Mathewb4c6df42022-11-09 11:13:29 +000030void plat_warmboot_setup(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3)
31{
32 /* Avoid MISRA C:2012-2.7 warnings */
33 (void)x0;
34 (void)x1;
35 (void)x2;
36 (void)x3;
37
38 if (plat_cmn_warmboot_setup() != 0) {
39 panic();
40 }
41}
42
43/*
44 * Global platform setup for RMM.
45 *
46 * This function will only be invoked once during cold boot
47 * and is expected to setup architecture and platform components
48 * common for all PEs executing RMM. The translation tables should
49 * be initialized by this function.
50 */
AlexeiFedorovb0de4d52023-10-10 11:46:16 +010051/* coverity[misra_c_2012_rule_8_7_violation:SUPPRESS] */
Soby Mathewb4c6df42022-11-09 11:13:29 +000052void plat_setup(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3)
53{
AlexeiFedorov7c5001a2022-12-14 13:22:33 +000054 int ret;
55 struct ns_dram_info *plat_dram;
Soby Mathew9dcdb152024-02-27 15:15:28 +000056 struct console_list *csl_list;
57 struct console_info *console_ptr;
Soby Mathewb4c6df42022-11-09 11:13:29 +000058
Javier Almansa Sobrinocd599e22023-06-28 12:28:00 +010059 /* TBD Initialize UART for early log */
60 struct xlat_mmap_region plat_regions[] = {
Soby Mathew9b2de242024-02-27 16:08:42 +000061 ARM_RMM_UART,
Javier Almansa Sobrinocd599e22023-06-28 12:28:00 +010062 {0}
63 };
64
Soby Mathew9dcdb152024-02-27 15:15:28 +000065 /* Initialize the RMM-EL3 interface*/
66 ret = plat_cmn_init_el3_ifc(x0, x1, x2, x3);
67 if (ret != E_RMM_BOOT_SUCCESS) {
68 rmm_el3_ifc_report_fail_to_el3(ret);
AlexeiFedorov44a76a32023-08-29 16:53:26 +010069 }
Soby Mathewb4c6df42022-11-09 11:13:29 +000070
Soby Mathew9dcdb152024-02-27 15:15:28 +000071 /* Initialize console first */
72 ret = rmm_el3_ifc_get_console_list_pa(&csl_list);
73 if (ret != 0) {
74 rmm_el3_ifc_report_fail_to_el3(ret);
75 }
76
77 /* If console_info is present, we need it to be pl011 */
78 if (csl_list->num_consoles != 0UL) {
79 uintptr_t uart_base;
80 unsigned int uart_clk, uart_baud;
81
82 console_ptr = &csl_list->consoles[0];
83
84 if (strncmp(console_ptr->name, "pl011", sizeof("pl011")) != 0) {
85 rmm_el3_ifc_report_fail_to_el3(E_RMM_BOOT_UNKNOWN_ERROR);
86 }
87
88 uart_base = console_ptr->base;
89 uart_clk = (unsigned int)console_ptr->clk_in_hz;
90 uart_baud = (unsigned int)console_ptr->baud_rate;
91
92 /* RMM currently only supports one console */
93 ret = pl011_init(uart_base, uart_clk, uart_baud);
94 if (ret != 0) {
95 rmm_el3_ifc_report_fail_to_el3(E_RMM_BOOT_UNKNOWN_ERROR);
96 }
97
98 plat_regions[0].base_pa = uart_base;
99 plat_regions[0].base_va = uart_base;
Javier Almansa Sobrinof6fff692024-02-02 17:13:57 +0000100 }
101
Mate Toth-Pal833bf632023-02-27 13:33:58 +0100102 /* Carry on with the rest of the system setup */
Soby Mathew9dcdb152024-02-27 15:15:28 +0000103 ret = plat_cmn_setup(plat_regions, 1U);
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +0000104 if (ret != 0) {
105 ERROR("%s (%u): Failed to setup the platform (%i)\n",
106 __func__, __LINE__, ret);
Javier Almansa Sobrinof6fff692024-02-02 17:13:57 +0000107 rmm_el3_ifc_report_fail_to_el3(E_RMM_BOOT_UNKNOWN_ERROR);
Soby Mathewb4c6df42022-11-09 11:13:29 +0000108 }
109
AlexeiFedorov7c5001a2022-12-14 13:22:33 +0000110 /*
111 * Validate DRAM data and get pointer
112 * to the platform DRAM info structure
113 */
114 ret = rmm_el3_ifc_get_dram_data_validated_pa(
Harry Moulton1c9c7b92024-03-07 16:33:59 +0000115 PLAT_ARM_MAX_DRAM_BANKS,
AlexeiFedorov7c5001a2022-12-14 13:22:33 +0000116 &plat_dram);
117 if (ret != E_RMM_BOOT_SUCCESS) {
118 ERROR("DRAM data error\n");
119 rmm_el3_ifc_report_fail_to_el3(ret);
120 }
121
Soby Mathew9b2de242024-02-27 16:08:42 +0000122 /* Set up Arm DRAM layout */
123 arm_set_dram_layout(plat_dram);
AlexeiFedorov7c5001a2022-12-14 13:22:33 +0000124
Soby Mathewb4c6df42022-11-09 11:13:29 +0000125 plat_warmboot_setup(x0, x1, x2, x3);
126}