Debian Codegraph @

plat/arm/board/neoverse_rd/platform/rdv3/rdv3_common.c

raw
1 /*
2 * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <common/debug.h>
8 #include <drivers/arm/gic600_multichip.h>
9 #include <drivers/arm/rse_comms.h>
10 #include <plat/arm/common/plat_arm.h>
11 #include <plat/common/platform.h>
12 #include <platform_def.h>
13 #include <nrd_plat.h>
14 #include <rdv3_mhuv3.h>
15 #include <rdv3_rse_comms.h>
16
17 unsigned int plat_arm_nrd_get_platform_id(void)
18 {
19 return mmio_read_32(SID_REG_BASE + SID_SYSTEM_ID_OFFSET) &
20 SID_SYSTEM_ID_PART_NUM_MASK;
21 }
22
23 unsigned int plat_arm_nrd_get_config_id(void)
24 {
25 return mmio_read_32(SID_REG_BASE + SID_SYSTEM_CFG_OFFSET);
26 }
27
28 unsigned int plat_arm_nrd_get_multi_chip_mode(void)
29 {
30 return (mmio_read_32(SID_REG_BASE + SID_NODE_ID_OFFSET) &
31 SID_MULTI_CHIP_MODE_MASK) >> SID_MULTI_CHIP_MODE_SHIFT;
32 }
33
34 /*
35 * Get a pointer to the RMM-EL3 shared buffer and return it
36 * through the pointer passed as parameter.
37 *
38 * This function returns the size of the shared buffer.
39 */
40 size_t plat_rmmd_get_el3_rmm_shared_mem(uintptr_t *shared)
41 {
42 *shared = (uintptr_t)RMM_SHARED_BASE;
43
44 return (size_t)RMM_SHARED_SIZE;
45 }
46
47 int plat_rmmd_load_manifest(struct rmm_manifest *manifest)
48 {
49 uint64_t checksum, num_banks, num_consoles;
50 struct ns_dram_bank *bank_ptr;
51 struct console_info *console_ptr;
52
53 assert(manifest != NULL);
54
55 /* DRAM Bank-1 and Bank-2 */
56 num_banks = 2;
57 assert(num_banks <= ARM_DRAM_NUM_BANKS);
58
59 /* Set number of consoles */
60 num_consoles = NRD_CSS_RMM_CONSOLE_COUNT;
61
62 manifest->version = RMMD_MANIFEST_VERSION;
63 manifest->padding = 0U; /* RES0 */
64 manifest->plat_data = (uintptr_t)NULL;
65 manifest->plat_dram.num_banks = num_banks;
66 manifest->plat_console.num_consoles = num_consoles;
67
68 /*
69 * Boot Manifest structure illustration, with two dram banks and
70 * a single console.
71 *
72 * +----------------------------------------+
73 * | offset | field | comment |
74 * +--------+----------------+--------------+
75 * | 0 | version | 0x00000003 |
76 * +--------+----------------+--------------+
77 * | 4 | padding | 0x00000000 |
78 * +--------+----------------+--------------+
79 * | 8 | plat_data | NULL |
80 * +--------+----------------+--------------+
81 * | 16 | num_banks | |
82 * +--------+----------------+ |
83 * | 24 | banks | plat_dram |
84 * +--------+----------------+ |
85 * | 32 | checksum | |
86 * +--------+----------------+--------------+
87 * | 40 | num_consoles | |
88 * +--------+----------------+ |
89 * | 48 | consoles | plat_console |
90 * +--------+----------------+ |
91 * | 56 | checksum | |
92 * +--------+----------------+--------------+
93 * | 64 | base 0 | |
94 * +--------+----------------+ bank[0] |
95 * | 72 | size 0 | |
96 * +--------+----------------+--------------+
97 * | 80 | base 1 | |
98 * +--------+----------------+ bank[1] |
99 * | 88 | size 1 | |
100 * +--------+----------------+--------------+
101 * | 96 | base | |
102 * +--------+----------------+ |
103 * | 104 | map_pages | |
104 * +--------+----------------+ |
105 * | 112 | name | |
106 * +--------+----------------+ consoles[0] |
107 * | 120 | clk_in_hz | |
108 * +--------+----------------+ |
109 * | 128 | baud_rate | |
110 * +--------+----------------+ |
111 * | 136 | flags | |
112 * +--------+----------------+--------------+
113 */
114
115 bank_ptr = (struct ns_dram_bank *)
116 (((uintptr_t)manifest) + sizeof(*manifest));
117 console_ptr = (struct console_info *)
118 ((uintptr_t)bank_ptr + (num_banks * sizeof(*bank_ptr)));
119
120 manifest->plat_dram.banks = bank_ptr;
121 manifest->plat_console.consoles = console_ptr;
122
123 /* Ensure the manifest is not larger than the shared buffer */
124 assert((sizeof(struct rmm_manifest) +
125 (sizeof(struct console_info) *
126 manifest->plat_console.num_consoles) +
127 (sizeof(struct ns_dram_bank) * manifest->plat_dram.num_banks))
128 <= ARM_EL3_RMM_SHARED_SIZE);
129
130 /* Calculate checksum of plat_dram structure */
131 checksum = num_banks + (uint64_t)bank_ptr;
132
133 /* Store FVP DRAM banks data in Boot Manifest */
134 bank_ptr[0].base = ARM_NS_DRAM1_BASE;
135 bank_ptr[0].size = ARM_NS_DRAM1_SIZE;
136
137 bank_ptr[1].base = ARM_DRAM2_BASE;
138 bank_ptr[1].size = ARM_DRAM2_SIZE;
139
140 /* Update checksum */
141 checksum += bank_ptr[0].base + bank_ptr[0].size + bank_ptr[1].base +
142 bank_ptr[1].size;
143
144 /* Checksum must be 0 */
145 manifest->plat_dram.checksum = ~checksum + 1UL;
146
147 /* Calculate the checksum of the plat_consoles structure */
148 checksum = num_consoles + (uint64_t)console_ptr;
149
150 /* Zero out the console info struct */
151 memset((void *)console_ptr, '\0',
152 sizeof(struct console_info) * num_consoles);
153
154 console_ptr[0].map_pages = 1;
155 console_ptr[0].base = NRD_CSS_RMM_CONSOLE_BASE;
156 console_ptr[0].clk_in_hz = NRD_CSS_RMM_CONSOLE_CLK_IN_HZ;
157 console_ptr[0].baud_rate = NRD_CSS_RMM_CONSOLE_BAUD;
158
159 strlcpy(console_ptr[0].name, NRD_CSS_RMM_CONSOLE_NAME,
160 sizeof(console_ptr[0].name));
161
162 /* Update checksum */
163 checksum += console_ptr[0].base + console_ptr[0].map_pages +
164 console_ptr[0].clk_in_hz + console_ptr[0].baud_rate;
165
166 /* Checksum must be 0 */
167 manifest->plat_console.checksum = ~checksum + 1UL;
168
169 return 0;
170 }
171
172 int plat_rse_comms_init(void)
173 {
174 uintptr_t snd_base, rcv_base;
175
176 /* Get sender and receiver frames for AP-RSE communication */
177 mhu_v3_get_secure_device_base(&snd_base, true);
178 mhu_v3_get_secure_device_base(&rcv_base, false);
179
180 VERBOSE("Initializing the rse_comms now\n");
181 /* Initialize the communication channel between AP and RSE */
182 return rse_comms_init(snd_base, rcv_base);
183 }