blob: a2f3b160a73c77d11ea388858c09332db8bae711 [file] [log] [blame]
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018 Intel Corporation <www.intel.com>
Naresh Kumar Ravulapalli94c40c02025-05-05 18:28:51 -07004 * Copyright (C) 2025 Altera Corporation <www.altera.com>
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -08005 */
6
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -08007#include <altera.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Tom Rinidec7ea02024-05-20 13:35:03 -06009#include <time.h>
Chee Hong Ang4e87fcd2020-08-07 11:50:04 +080010#include <watchdog.h>
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -080011#include <asm/arch/mailbox_s10.h>
Chee Hong Angec4c6792020-12-24 18:21:07 +080012#include <asm/arch/smc_api.h>
Naresh Kumar Ravulapalli94c40c02025-05-05 18:28:51 -070013#include <asm/cache.h>
14#include <cpu_func.h>
Simon Glassdbd79542020-05-10 11:40:11 -060015#include <linux/delay.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060016#include <linux/errno.h>
Chee Hong Angec4c6792020-12-24 18:21:07 +080017#include <linux/intel-smc.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060018#include <linux/string.h>
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -080019
20#define RECONFIG_STATUS_POLL_RESP_TIMEOUT_MS 60000
21#define RECONFIG_STATUS_INTERVAL_DELAY_US 1000000
22
Simon Glass7ec24132024-09-29 19:49:48 -060023#if !defined(CONFIG_XPL_BUILD) && defined(CONFIG_SPL_ATF)
Chee Hong Angec4c6792020-12-24 18:21:07 +080024
25#define BITSTREAM_CHUNK_SIZE 0xFFFF0
26#define RECONFIG_STATUS_POLL_RETRY_MAX 100
27
Boon Khai Ng483a1bb2025-01-17 14:33:31 +080028static const struct mbox_cfgstat_major_err {
29 int err_no;
30 const char *error_name;
31} mbox_cfgstat_major_err[] = {
32 {MBOX_CFGSTATE_MAJOR_ERR_WRONG_BL31_VER,
33 "Please check ATF BL31 version, require v2.11 above to print more error status."},
34 {MBOX_CFGSTATE_MAJOR_ERR_STATE_CONFIG,
35 "Mailbox in configuration state."},
36 {MBOX_CFGSTATE_MAJOR_ERR_BITSTREAM_ERR,
37 "Bitstream Invalid."},
38 {MBOX_CFGSTATE_MAJOR_ERR_EXT_HW_ACCESS_FAIL,
39 "External HW access failure."},
40 {MBOX_CFGSTATE_MAJOR_ERR_BITSTREAM_CORRUPTION,
41 "Bitstream valid but corrupted. Bitstream corruption error when reading the bitstream from the source."
42 },
43 {MBOX_CFGSTATE_MAJOR_ERR_INTERNAL_ERR,
44 "Bitstream element not understood. Internal error."},
45 {MBOX_CFGSTATE_MAJOR_ERR_DEVICE_ERR,
46 "Unable to communicate on internal configuration network. Device operation error."},
47 {MBOX_CFGSTATE_MAJOR_ERR_HPS_WDT,
48 "HPS Watchdog Timer. HPS watchdog timeout failure."},
49 {MBOX_CFGSTATE_MAJOR_ERR_INTERNAL_UNKNOWN_ERR,
50 "Other unknown error occurred"},
51 {MBOX_CFGSTATE_MAJOR_ERR_SYSTEM_INIT_ERR,
52 "Error before main CMF start. System initialization failure."},
53 {MBOX_CFGSTATE_MAJOR_ERR_DECRYPTION_ERR,
54 "Decryption Error."},
55 {MBOX_CFGSTATE_MAJOR_ERR_VERIFY_IMAGE_ERR,
56 "Verify image error."},
57 {MBOX_CFGSTATE_MAJOR_ERR_UNK,
58 "Unknown error number at major field!"}
59};
60
61#define MBOX_CFGSTAT_MAJOR_ERR_MAX ARRAY_SIZE(mbox_cfgstat_major_err)
62
63static const struct mbox_cfgstat_minor_err {
64 int err_no;
65 const char *error_name;
66} mbox_cfgstat_minor_err[] = {
67 {MBOX_CFGSTATE_MINOR_ERR_BASIC_ERR,
68 "Catchall Error."},
69 {MBOX_CFGSTATE_MINOR_ERR_CNT_RESP_ERR,
70 "Detected an error during configuration. Detected an error during configuration."
71 },
72 {MBOX_CFGSTATE_MINOR_ERR_QSPI_DEV_ERR,
73 "QSPI Device related error. Detected QSPI device related error during configuration."
74 },
75 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_INV,
76 "Bitstream section main descriptor invalid. Detected an error during configuration due to a corrupted bitstream."
77 },
78 {MBOX_CFGSTATE_MINOR_ERR_BS_INCOMPATIBLE,
79 "Bistream not compatible with device. Detected an error during configuration due to incompatible bitstream with the device."
80 },
81 {MBOX_CFGSTATE_MINOR_ERR_BS_INV_SHA,
82 "Bitstream invalid SHA setting. Detected an error during configuration due to a corrupted bitstream."
83 },
84 {MBOX_CFGSTATE_MINOR_ERR_ROUTE_FAIL,
85 "Bitstream processing route failed. Detected an error during configuration due to a corrupted bitstream."
86 },
87 {MBOX_CFGSTATE_MINOR_ERR_GO_BIT_ALREADY_SET,
88 "Failed DMA during bitstream processing. Detected an error during configuration due to a corrupted bitstream."
89 },
90 {MBOX_CFGSTATE_MINOR_ERR_CPU_BLK_FAIL,
91 "Failed DMA during bitstream processing. Detected an error during configuration."
92 },
93 {MBOX_CFGSTATE_MINOR_ERR_ACT_SKIP_FAIL,
94 "Skip action failed. Detected an error during configuration."},
95 {MBOX_CFGSTATE_MINOR_ERR_ACT_MCAST_FAIL,
96 "Multicast Action Failed. Detected an error during configuration."},
97 {MBOX_CFGSTATE_MINOR_ERR_ACT_IND_SZ_FAIL,
98 "Index Size Action Failed. Detected an error during configuration."},
99 {MBOX_CFGSTATE_MINOR_ERR_ACT_IF_FAIL,
100 "If Action Failed. Detected an error during configuration."},
101 {MBOX_CFGSTATE_MINOR_ERR_ACT_PIN_FAIL,
102 "Pin Action Failed. Detected an error during configuration."},
103 {MBOX_CFGSTATE_MINOR_ERR_ACT_FUSEFLTR_FAIL,
104 "Fuse Filter Action Failed. Detected an error during configuration."},
105 {MBOX_CFGSTATE_MINOR_ERR_ACT_GENERIC_FAIL,
106 "Other Action Failed. Detected an error during configuration."},
107 {MBOX_CFGSTATE_MINOR_ERR_DATA_STARVE_ERR,
108 "Datapath starved. Detected an error during configuration."},
109 {MBOX_CFGSTATE_MINOR_ERR_CNT_RAM_INIT_FAIL,
110 "CNT/SSM RAM Initialization Failed. Detected an error during configuration."},
111 {MBOX_CFGSTATE_MINOR_ERR_ACT_SETUP_S4,
112 "S4 Setup Failed. Detected an error during configuration."},
113 {MBOX_CFGSTATE_MINOR_ERR_WIPE_DATA_STARVE,
114 "Datapath starved during wipe. Detected an error during configuration."},
115 {MBOX_CFGSTATE_MINOR_ERR_FUSE_RD_FAIL,
116 "eFUSE Read Failure. Detected an error during configuration."},
117 {MBOX_CFGSTATE_MINOR_ERR_AUTH_FAIL,
118 "Authentication Failure. Detected a bitstream authentication error during configuration."
119 },
120 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_SHA_FAIL,
121 "Bitstream Section Main Descriptor Hash Check Failed. Detected an error during configuration due to a corrupted bitstream."
122 },
123 {MBOX_CFGSTATE_MINOR_ERR_SKIP_DATA_RAM_FAIL,
124 "Skip Action Failed. Detected an error during configuration."},
125 {MBOX_CFGSTATE_MINOR_ERR_ACT_FIXED_FAIL,
126 "Fixed Action Failed. Detected an error during configuration."},
127 {MBOX_CFGSTATE_MINOR_ERR_ACT_MCAST_FLTR_FAIL,
128 "Multicast Filter Action Failed. Detected an error during configuration."},
129 {MBOX_CFGSTATE_MINOR_ERR_ACT_SECTOR_FAIL,
130 "Sector Group Action Failed. Detected an error during configuration."},
131 {MBOX_CFGSTATE_MINOR_ERR_ACT_HASH_FAIL,
132 "Hash Action Failed. Detected an error during configuration."},
133 {MBOX_CFGSTATE_MINOR_ERR_ACT_DECOMP_SETUP_FAIL,
134 "Decompression Setup Action Failed. Detected an error during configuration."},
135 {MBOX_CFGSTATE_MINOR_ERR_INTERNAL_OS_ERR,
136 "RTOS Error. Detected an error during configuration."},
137 {MBOX_CFGSTATE_MINOR_ERR_WIPE_FAIL,
138 "Wipe Bitstream Failed. Detected an error during configuration."},
139 {MBOX_CFGSTATE_MINOR_ERR_CNOC_ERR,
140 "Internal Configuration Network Failure. Detected an error during configuration."
141 },
142 {MBOX_CFGSTATE_MINOR_ERR_PMF_RESUME_FAIL,
143 "Power Management Firmware Failed Resume. Detected an error during configuration."
144 },
145 {MBOX_CFGSTATE_MINOR_ERR_PMF_RUN_FAIL,
146 "Power Management Firmware Failed Run. Detected an error during configuration."},
147 {MBOX_CFGSTATE_MINOR_ERR_PMF_PAUSE_FAIL,
148 "Power Management Firmware Failed Pause. Detected an error during configuration."
149 },
150 {MBOX_CFGSTATE_MINOR_ERR_RET_INT_ASSERT_FAIL,
151 "Internal Configuration Network Return Interrupt Failure. Detected an error during configuration."
152 },
153 {MBOX_CFGSTATE_MINOR_ERR_STATE_MACHINE_ERR,
154 "Configuration State Machine Error. Detected an error during configuration."},
155 {MBOX_CFGSTATE_MINOR_ERR_CMF_TRANSITION_FAIL,
156 "Error during CMF load/reload. Detected a firmware transition error during configuration."
157 },
158 {MBOX_CFGSTATE_MINOR_ERR_SHA_SETUP_FAIL,
159 "Error setting up SHA engine. Detected an error during configuration."},
160 {MBOX_CFGSTATE_MINOR_ERR_WR_DMA_TIMEOUT,
161 "Write DMA timed out. Detected an error during configuration."},
162 {MBOX_CFGSTATE_MINOR_ERR_MEM_ALLOC_FAIL,
163 "Out of Memory. Detected an error during configuration."},
164 {MBOX_CFGSTATE_MINOR_ERR_SYNC_RD_FAIL,
165 "Sync Block Read Fail. Detected an error during configuration."},
166 {MBOX_CFGSTATE_MINOR_ERR_CHK_CFG_REQ_FAIL,
167 "Configuration Status Check Failed. Detected an error during configuration."},
168 {MBOX_CFGSTATE_MINOR_ERR_HPS_CFG_REQ_FAIL,
169 "HPS Configuration Request Failed. Detected an error during configuration."},
170 {MBOX_CFGSTATE_MINOR_ERR_CFG_HANDLE_ERR,
171 "Driver Handle Error. Detected an error during configuration."},
172 {MBOX_CFGSTATE_MINOR_ERR_INV_ACTION_ITEM,
173 "Bistream contains invalid action. Detected an error during configuration."},
174 {MBOX_CFGSTATE_MINOR_ERR_SKIP_DATA_PREBUF_ERR,
175 "Prebuffer Error during Skip Action. Detected an error during configuration."},
176 {MBOX_CFGSTATE_MINOR_ERR_MBOX_TIMEOUT,
177 "Mailbox Processing Timeout. Detected an error during configuration."},
178 {MBOX_CFGSTATE_MINOR_ERR_AVST_FIFO_OVERFLOW_ERR,
179 "AVST FIFO Overflow. Detected an error during configuration."},
180 {MBOX_CFGSTATE_MINOR_ERR_RD_DMA_TIMEOUT,
181 "Read DMA timed out. Detected an error during configuration."},
182 {MBOX_CFGSTATE_MINOR_ERR_PMF_INIT_ERR,
183 "Power Management Firmware Initialization Error. Detected a PMBUS error during configuration."
184 },
185 {MBOX_CFGSTATE_MINOR_ERR_PMF_SHUTDOWN_ERR,
186 "Power Management Firmware Shutdown Error. Detected a PMBUS error during configuration."
187 },
188 {MBOX_CFGSTATE_MINOR_ERR_BITSTREAM_INTERRUPTED,
189 "Bitstream processing was interrupted by another event. Detected an error during configuration."
190 },
191 {MBOX_CFGSTATE_MINOR_ERR_FPGA_MBOX_WIPE_TIMEOUT,
192 "Mailbox Wipe Timeout. Detected an error during configuration."},
193 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_TYPE_INV,
194 "Bitstream Section Main Descriptor Type is Invalid. Detected an error during configuration due to a corrupted bitstream."
195 },
196 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_VERSION_INV,
197 "Bitstream Section Main Descriptor Version is Invalid. Detected an error during configuration due to a corrupted bitstream."
198 },
199 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_DEVICE_TYPE_INV,
200 "Bitstream Section Main Descriptor Device is Invalid. Detected an error during configuration due to a corrupted bitstream."
201 },
202 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_DESIGN_HASH_ERR,
203 "Bitstream Section Main Descriptor Hash Mismatch. Detected an error during configuration due to a corrupted bitstream."
204 },
205 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_EXT_REF_CLK_ERR,
206 "Bitstream Section Main Descriptor External Clock Setting Invalid. Detected an error during configuration due to a corrupted bitstream."
207 },
208 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_PWR_TBL_INV,
209 "Bitstream Section Main Descriptor Power Table is invalid. Detected an error during configuration due to a corrupted bitstream."
210 },
211 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_PIN_TBL_OFST_ERR,
212 "Bitstream Section Main Descriptor Offset to Pin Table is Invalid. Detected an error during configuration due to a corrupted bitstream."
213 },
214 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_PIN_TBL_INV,
215 "Bitstream Section Main Descriptor Pin Table is Invalid. Detected an error during configuration due to a corrupted bitstream."
216 },
217 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_NO_PIN_TBL,
218 "Bitstream Section Main Descriptor missing pin table. Detected an error during configuration due to a corrupted bitstream."
219 },
220 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_CFG_CLK_PLL_FAILED,
221 "Bitstream Section Main Descriptor PLL setting failure. Detected an error during configuration due to a corrupted bitstream."
222 },
223 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_AS_CLK_FAILED,
224 "Bitstream Section Main Descriptor QSPI Clock Setting Failure. Detected an error during configuration due to a corrupted bitstream."
225 },
226 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_POF_ID_FAILED,
227 "Bitstream Section Main Descriptor POF ID not valid. Detected an incompatible PR bitstream during configuration."
228 },
229 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_PW_TBL_OFST_ERR,
230 "code not used."},
231 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_PP_TBL_OFST_ERR,
232 "code not used."},
233 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_PP_TBL_INV,
234 "code not used."},
235 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_SP_TBL_OFST_ERR,
236 "code not used."},
237 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_SP_TBL_INV,
238 "code not used."},
239 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_SU_TBL_OFST_ERR,
240 "code not used."},
241 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_SU_TBL_INV,
242 "code not used."},
243 {MBOX_CFGSTATE_MINOR_ERR_MBOX_TASK_CRYPTO_SRC_CLR_ERR,
244 "Mailbox Source Failed to Clear. Detected an error during configuration."},
245 {MBOX_CFGSTATE_MINOR_ERR_MBOX_TASK_EVENT_GROUP_POST_ERR,
246 "Mailbox Event Post Error. Detected an error during configuration."},
247 {MBOX_CFGSTATE_MINOR_ERR_TRNG_TEST_FAIL,
248 "True Random Number Generator Failed Test. Detected an error during configuration."
249 },
250 {MBOX_CFGSTATE_MINOR_ERR_MBOX_TASK_ANTI_DOS_TMR_INIT_ERR,
251 "Mailbox Anti-DOS Timer failed initialization. Detected an error during configuration."
252 },
253 {MBOX_CFGSTATE_MINOR_ERR_OS_STK_CHK_ERR,
254 "RTOS Stack Check Error. Detected an error during configuration."},
255 {MBOX_CFGSTATE_MINOR_ERR_MBOX_TASK_INIT,
256 "Mailbox Task failed to initialize. Detected an error during configuration."},
257 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_COMPAT_ID_MATCH_ERR,
258 "Bitstream Section Main Descriptor Compatibility ID mismatch. Detected a bitstream error during configuration."
259 },
260 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_COMPAT_ID_INV,
261 "Bitstream Section Main Descriptor Compatibility ID not Valid. Detected an error during configuration due to a corrupted bitstream."
262 },
263 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_AES_ECRYPT_CHK_FAIL,
264 "Bitstream Section Main Descriptor AES Test Failed. Detected an error during configuration due to a corrupted bitstream."
265 },
266 {MBOX_CFGSTATE_MINOR_ERR_ACT_KEY_FAIL,
267 "Key Action Failure. Detected a bitstream decryption error during configuration due to a corrupted bitstream."
268 },
269 {MBOX_CFGSTATE_MINOR_ERR_ACT_KEY_CHALLENGE_FAIL,
270 "Key Challenge Failure. Detected a bitstream decryption error during configuration."
271 },
272 {MBOX_CFGSTATE_MINOR_ERR_MBOX_TASK_MSGQ_DEQUEUE_FAIL,
273 "Mailbox Task Queue failed to dequeue. Detected an error during configuration."},
274 {MBOX_CFGSTATE_MINOR_ERR_SECT_COMPAT_CHK_ERR,
275 "Bitstream Section Compatibility Check Error. Detected an error during configuration due to a corrupted bitstream."
276 },
277 {MBOX_CFGSTATE_MINOR_ERR_SECT_COMPAT_UPDATE_ERR,
278 "Bitstream Section Compatibility Update Error. Detected an error during configuration due to a corrupted bitstream."
279 },
280 {MBOX_CFGSTATE_MINOR_ERR_SECT_SEC_CHK_FAILED,
281 "Bitstream Section Security Check Failed. Detected an error during configuration due to a corrupted bitstream."
282 },
283 {MBOX_CFGSTATE_MINOR_ERR_CNT_RAM_ECC_ERR_UNRECOVERABLE,
284 "Unrecoverable Error in CNT/SSM RAM. Detected an error during configuration."},
285 {MBOX_CFGSTATE_MINOR_ERR_MBOX_REFORMAT_INPUT_ERR,
286 "Mailbox Input Processing Error. Detected an error during configuration."},
287 {MBOX_CFGSTATE_MINOR_ERR_MBOX_REFORMAT_OUTPUT_ERR,
288 "Mailbox Output Processing Error. Detected an error during configuration."},
289 {MBOX_CFGSTATE_MINOR_ERR_MBOX_WLBL_ERR,
290 "(Provision only) Provision CMF's allowed mailbox cmd group is invalid. Detected an error during configuration."
291 },
292 {MBOX_CFGSTATE_MINOR_ERR_MBOX_HOOK_CB_ERR,
293 "Mailbox Callback Error. Detected an error during configuration."},
294 {MBOX_CFGSTATE_MINOR_ERR_CMF_RLD_DECOMP_LOAD_ERR,
295 "CMF Reload failed to load Decompression Code. Detected an error during configuration."
296 },
297 {MBOX_CFGSTATE_MINOR_ERR_CMF_RLD_DECOMP_RUN_ERR,
298 "CMF Reload failed to run Decompression Code. Detected an error during configuration."
299 },
300 {MBOX_CFGSTATE_MINOR_ERR_CNT_PERIPH_ECC_ERR_UNRECOVERABLE,
301 "Unrecoverable Error in CNT/SSM Peripheral. Detected an error during configuration."
302 },
303 {MBOX_CFGSTATE_MINOR_ERR_MAIN_SECT_ADDR_ERR,
304 "(Provision only) invalid Flash image CMF header's main section address. Detected an error during configuration."
305 },
306 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_SCRAMBLE_RATIO_CHK_FAIL,
307 "Bitstream Section Main Descriptor Invalid Scrambler Ratio. Detected an error during configuration due to a corrupted bitstream."
308 },
309 {MBOX_CFGSTATE_MINOR_ERR_TAMPER_EVENT_TRIGGERED,
310 "Tamper Detected. Detected an error during configuration."},
311 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_ANTI_TAMPER_TBL_INV,
312 "Bitstream Section Main Descriptor Anti Tamper Table Invalid. Detected an error during configuration due to a corrupted bitstream."
313 },
314 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_EXT_CLCK_MODE_DISALLOWED,
315 "External Clock info presented, but external clock not allowed on device. Detected an error during configuration due to a corrupted bitstream."
316 },
317 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_SEC_OPTIONS_INIT_FAIL,
318 "Bitstream Section Main Descriptor Security Option Initialization Failed. Detected an error during configuration due to a corrupted bitstream."
319 },
320 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_EN_USR_CAN_FUSE_INV,
321 "User cancellation fuse table initialization failed. Detected an error during configuration."
322 },
323 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_AS_DEVICE_NO_SGX_ERR,
324 "Not yet turned on for Rearch code. Detected an incompatible bitstream during configuration. You cannot use the bitstream from an advanced security-enabled devices on a non-advanced security-enabled device."
325 },
326 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_POF_ID_LIMIT_EXCEED_ERR,
327 "Not yet turned on for Rearch code. Detected an invalid bitstream during configuration."
328 },
329 {MBOX_CFGSTATE_MINOR_ERR_PROVISION_CMF_INV_STATE,
330 "(Provision only) Internal state machine wrong state. Detected an error during configuration."
331 },
332 {MBOX_CFGSTATE_MINOR_ERR_PROVISION_CMF_FATAL_ERR,
333 "(Provision only) Fatal error detected with Provision CMF. Detected an error during configuration."
334 },
335 {MBOX_CFGSTATE_MINOR_ERR_PROVISION_CMF_SM_EXIT_FAIL,
336 "(Provision only) State machine's state function exit error. Detected an error during configuration."
337 },
338 {MBOX_CFGSTATE_MINOR_ERR_PROVISION_CMF_SM_ENTRY_FAIL,
339 "(Provision only) State machine's state function entry error. Detected an error during configuration."
340 },
341 {MBOX_CFGSTATE_MINOR_ERR_ACTION_DATA_UNSUPPORTED_CTX,
342 "Not yet turned on for Rearch code. Detected an error during configuration."},
343 {MBOX_CFGSTATE_MINOR_ERR_CMF_EXCEPTION,
344 "Processor Exception. Detected an error during configuration."},
345 {MBOX_CFGSTATE_MINOR_ERR_ECC_INIT_FAIL,
346 "SDM Peripheral ECC Initialization Failure. Detected an error during configuration."
347 },
348 {MBOX_CFGSTATE_MINOR_ERR_DEFAULT_UNREGISTERED_ISR,
349 "Unregistered Interrupt Occurred. Detected an error during configuration."},
350 {MBOX_CFGSTATE_MINOR_ERR_GENERAL_TIMEOUT,
351 "Execution Timeout. Detected an error during configuration."},
352 {MBOX_CFGSTATE_MINOR_ERR_ACT_OPERATION_CLK_FAIL,
353 "Clock Operation Action Failed. Detected an error during configuration."},
354 {MBOX_CFGSTATE_MINOR_ERR_ACT_VERIFY_HASH_FAIL,
355 "Verify Hash Action Failed. Detected an error during configuration."},
356 {MBOX_CFGSTATE_MINOR_ERR_CFG_STATE_UPDATE_ERR,
357 "Error updating configuration state. Detected an error during configuration."},
358 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_READ_DDR_HASH_FAIL,
359 "Error while reading HPS DDR hash from main descriptor."},
360 {MBOX_CFGSTATE_MINOR_ERR_CVP_FLOW_ERR,
361 "Error during CvP Phase 2 data flow handling or handshake."},
362 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_KEYED_HASH_ERR,
363 "Encountered keyed hash error while processing a main descriptor."},
364 {MBOX_CFGSTATE_MINOR_ERR_CMF_DESC_BAD_JTAG_ID,
365 "New CMF Descriptor JTAG ID mismatch with original configured CMF JTAG ID."
366 },
367 {MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_PMF_NOT_SUPPORTED,
368 "The IO Descriptor contains a power table but the current CMF does not support PMF. Bitstream incompatile with Firmware."
369 },
370 {
371 MBOX_CFGSTATE_MINOR_ERR_MAIN_DESC_ANTI_TAMPER_NOT_SUPPORTED,
372 "The IO Descriptor contains anti-tamper setting but the current CMF does not support anti-tamper. Bitstream incompatile with Firmware."
373 },
374 {MBOX_CFGSTATE_MINOR_ERR_ACT_RECOVERY_FAIL,
375 "Recovery Action Failed. Detected an error during configuration."},
376 {MBOX_CFGSTATE_MINOR_ERR_COLD_RESET_CMF_CORRUPTED,
377 "Error when process CMF section after cold reset. Detected CMF section error or incompatible upon cold reset using JTAG or AVST."
378 },
379 {MBOX_CFGSTATE_MINOR_ERR_COLD_RESET_IO_HPS_CORRUPTED,
380 "Error when process IO/HPIO/HPS section after cold reset and hps wipe. Detected an error when try to bring up HPS again after cold reset."
381 },
382 {MBOX_CFGSTATE_MINOR_ERR_COLD_RESET_FPGA_CORRUPTED,
383 "Error when process FPGA section header after cold reset. Detected an error in FPGA after successfully bring up HPS."
384 },
385 {MBOX_CFGSTATE_MINOR_ERR_CRC_CHK_FAIL,
386 " CRC32 Check Fail. Detected an error during configuration."},
387 {MBOX_CFGSTATE_MINOR_ERR_COMPAT_TBL_SFIXED_VALUE_INV,
388 "Error when process compatibility table in main section header. SFixed offset value in compatibility table is not valid."
389 },
390 {
391 MBOX_CFGSTATE_MINOR_ERR_FEATURE_EN_FUSE_NOT_BLOWN,
392 "Error bitstream contains feature(s) that are only allowed when a feature fuse is blown on the device, and the device did not have the feature fuse blown. Bitstream requires feature enable fuse to be blown."
393 },
394 {MBOX_CFGSTATE_MINOR_ERR_UIB_REFCLK_MISSING,
395 "UIB REFCLK missing. Device requires refclk to proceed configuration."},
396 {MBOX_CFGSTATE_MINOR_ERR_UIB_REFCLK_TIMEOUT,
397 "UIB REFCLK timeout. Device requires refclk to proceed configuration."},
398 {MBOX_CFGSTATE_MINOR_ERR_UIB_REFCLK_TIMEOUT_MISSING,
399 "UIB REFCLK missing and timeout. Device requires refclk to proceed configuration."
400 },
401 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_SYNC_BLCK_ERR,
402 "Sync block before SSBL processing failure. Detected a firmware error during reconfiguration."
403 },
404 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_SSBL_SHA_ERR,
405 "SSBL sha mismatch with bitstream. Detected a bitstream error during reconfiguration."
406 },
407 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_BLCK0_SHA_MISMATCH_ERR,
408 "Block0 Sha mismatch when trampoline reloads. Detected a bitstream error during reconfiguration."
409 },
410 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_BLCK0_AUTH_ERR,
411 "Trampoline authentication failure. Detected a bitstream error during reconfiguration."
412 },
413 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_TRAMP_LOAD_ERR,
414 "Trampoline Load compressed tramp failure. Detected a bitstream error during reconfiguration."
415 },
416 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_CMF_SIZE_ERR,
417 "Trampoline failed to retrieve SSBL or TSBL load information. Detected a bitstream error during reconfiguration."
418 },
419 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_TRANSITION_ERR,
420 "Trampoline failed to find a bootable DCMF. Detected an error during application images transition."
421 },
422 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_SYNC_ERR,
423 "Only used by RMA and ENG loader on legacy code. Detected an error during configuration."
424 },
425 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_LOAD_CERT_ERR,
426 "Main CMF failed to authenticate a certificate bitstream. Detected a bitstream authentication error during reconfiguration."
427 },
428 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_LOAD_NOT_ALLOWED_ERR,
429 "Only used by Provision CMF, failure to initialize HW drivers. Detected an error during reconfiguration."
430 },
431 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_FUSE_ERR,
432 "Only used by RMA and Eng loader on Legacy code. Detected an error during configuration."
433 },
434 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_INPUT_BUFFER_ERR,
435 "Provision CMF only, Trampoline inbuf HW access error. Detected a hardware error during reconfiguration."
436 },
437 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_CMF_TYPE_ERR,
438 "Trampoline/DCMF loading another CMF andfound CMF type mismatched with current one. Detected a bitstream error during reconfiguration."
439 },
440 {MBOX_CFGSTATE_MINOR_ERR_TRAMP_QSPI_INDR_READ_START_ERR,
441 "Trampoline QSPI indirect read start error. Detected an error when accessing the QSPI flash."
442 },
443 {MBOX_CFGSTATE_MINOR_ERR_PMF_I2C_COMM_ERR,
444 "Generic I2C error, ie Bad Address."},
445 {MBOX_CFGSTATE_MINOR_ERR_PMF_TARGET_VOLTAGE_ERR,
446 "Failed to reach Target Voltage. Voltage Regulator unable to achieve the requested voltage."
447 },
448 {MBOX_CFGSTATE_MINOR_ERR_PMF_HANDSHAKE_ERR,
449 "Slave Mode ALERT/VOUT_COMMAND handshake did not happen."},
450 {MBOX_CFGSTATE_MINOR_ERR_PMF_ITD_OUT_OF_RANGE_ERR,
451 "Fuse values calculated voltage greater that cutoff max. ITD fuse is out of range."
452 },
453 {MBOX_CFGSTATE_MINOR_ERR_PMF_PWR_TABLE_ERR,
454 "Error while reading or processing the Power Table. Internal Error while reading or decoding the Bitstream's Power Table."
455 },
456 {MBOX_CFGSTATE_MINOR_ERR_PMF_EFUSE_DECODE_ERR,
457 "Error while reading or decoding the efuse values. Internal Error while reading or decoding the efuse values."
458 },
459 {MBOX_CFGSTATE_MINOR_ERR_PMF_VCCL_PWRGOOD_ERR,
460 "Failed to verify the vccl power is good. Failed to validate the vccl power is valid on the board."
461 },
462 {MBOX_CFGSTATE_MINOR_ERR_PMF_CLR_FAULTS_ERR,
463 "Error while sending CLEAR_FAULTS command. Error while sending CLEAR_FAULTS command,"
464 },
465 {MBOX_CFGSTATE_MINOR_ERR_PMF_VOUT_MODE_ERR,
466 "Error while sending VOUT_MODE command. Error while sending VOUT_MODE command,"},
467 {MBOX_CFGSTATE_MINOR_ERR_PMF_PAGE_COMMAND_ERR,
468 "Error while sending PAGE_COMMAND command. Error while sending PAGE_COMMAND command,"
469 },
470 {MBOX_CFGSTATE_MINOR_ERR_PMF_VOUT_COMMAND_ERR,
471 "Error while sending VOUT_COMMAND command. Error while sending VOUT_COMMAND command,"
472 },
473 {MBOX_CFGSTATE_MINOR_ERR_PMF_READ_VOUT_ERR,
474 "Error while sending READ_VOUT command. Error while sending READ_VOUT command,"},
475 {MBOX_CFGSTATE_MINOR_ERR_PMF_LTM4677_DEFAULT_ADC_CTRL_ERR,
476 "Error while sending the vendor specific LTM4677 MFR_ADC_CTRL command. Error while sending the vendor specific LTM4677 MFR_ADC_CTRL command,"
477 },
478 {MBOX_CFGSTATE_MINOR_ERR_PMF_FIRST_I2C_CMD_FAILED_ERR,
479 "First I2C messaged failed, ie Bad Address. The first I2C command has failed, no response from Voltage Regulator."
480 },
481 {MBOX_CFGSTATE_MINOR_ERR_RSU_CMF_AUTH_ERR,
482 "Failed to authenticate CMF section. Detected a firmware authentication error during configuration."
483 },
484 {MBOX_CFGSTATE_MINOR_ERR_RSU_USER_AUTH_ERR,
485 "Failed to authenticate USER section. Detected a bitstream authentication error during configuration."
486 },
487 {MBOX_CFGSTATE_MINOR_ERR_RSU_CMF_DESC_SHA_MISMATCH,
488 "Block0 SHA mismatch when DCMF loads an APP image. Detected an error when loading the application image from flash."
489 },
490 {MBOX_CFGSTATE_MINOR_ERR_RSU_POINTERS_NOT_FOUND_ERR,
491 "RSU CPB table parsing failed. Detected an error when parsing the RSU CPB block."
492 },
493 {MBOX_CFGSTATE_MINOR_ERR_RSU_QSPI_FREQ_CHANGE,
494 "QSPI reference clock freq update failed. Detected an error during configuration."
495 },
496 {MBOX_CFGSTATE_MINOR_ERR_RSU_FACTORY_IMG_FAILED,
497 "RSU factory image failed to boot. Detected an error when loading the factory image. Check the factory image validity. If corrupted, regenerate and reprogram again the factory image in the flash. When authentication enabled,"
498 },
499 {MBOX_CFGSTATE_MINOR_ERR_RSU_CMF_TYPE_ERR,
500 "APP image CMF type mismatched with DCMF. Detected an error when loading the application image."
501 },
502 {
503 MBOX_CFGSTATE_MINOR_ERR_RSU_UCMF_SIG_DESC_ERR,
504 "UCMF reports failure in parsing of an signature block, can be from new DCMF, new DCIO or new Factory. Detected an error during factory image update in flash."
505 },
506 {MBOX_CFGSTATE_MINOR_ERR_RSU_UCMF_INTERNAL_AUTH_ERR,
507 "UCMF reports authentication failure of new DCMF, new DCIO or new Factory. Detected an error during DCMF update in flash."
508 },
509 {MBOX_CFGSTATE_MINOR_ERR_RSU_UCMF_COPY_FAILED,
510 "UCMF reports QSPI flash write failure while upgrading DCMF, DCIO or Factory. Detected an error during DCMF update in flash."
511 },
512 {MBOX_CFGSTATE_MINOR_ERR_RSU_UCMF_ERASE_FAILED,
513 "UCMF reports QSPI flash erase failure while upgrading DCMF, DCIO or Factory. Detected an error during DCMF update in flash."
514 },
515 {MBOX_CFGSTATE_MINOR_ERR_RSU_RM_UCMF_FROM_CPB_FAILED,
516 "UCMF reports failure to remove UCMF address from RSU CPB table. Detected an error during RSU CPB table update in flash."
517 },
518 {MBOX_CFGSTATE_MINOR_ERR_RSU_UCMF_COMBINED_APP_AUTH_ERR,
519 "UCMF reports authentication failure of new combined app image. Detected an error during combined app image update in flash."
520 },
521 {MBOX_CFGSTATE_MINOR_ERR_RSU_UCMF_FLASH_ACCESS_ERR,
522 "UCMF failed to upgrade for more than max retry times. Detected an error during DCMF update in flash."
523 },
524 {MBOX_CFGSTATE_MINOR_ERR_RSU_DCMF_DCIO_CORRUPTED,
525 "DCMF reports failure when parse dcio section, causing force factory boot. Detected an error when parsing dcio section."
526 },
527 {MBOX_CFGSTATE_MINOR_ERR_RSU_DCMF_CPB0_CORRUPTED,
528 "DCMF reports failure when parse cpb0 and thus cpb1 is used. Detected an error in RSU CPB0 table."
529 },
530 {MBOX_CFGSTATE_MINOR_ERR_RSU_DCMF_CPB1_CORRUPTED,
531 "DCMF reports failure when parse both cpb0 and cpb1, causing force factory boot. Detected an error in both RSU CPB0 and CPB1 table."
532 },
533 {MBOX_CFGSTATE_MINOR_ERR_RSU_PROVISION_COMPLETE,
534 "Non-JTAG Provisioning Successful. Non-Jtag Provisioning was Successful DCMF will load next highest priority application image."
535 },
536 {MBOX_CFGSTATE_MINOR_ERR_RSU_PROVISION_ERR,
537 "Non-JTAG Provisioning Failed. An error occurred while provisioning the device."},
538 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_EFUSE_INIT_FAIL,
539 "Efuse cache generation failure. Detected an error during configuration."},
540 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_SEC_PROT_ERR,
541 "Security lock and disable driver failure. Detected an error during configuration."
542 },
543 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_EFUSE_LCK_ERR,
544 "efuse lock operation failure."},
545 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_SEC_BBRAM_CLEAN_ERR,
546 "BBRAM clean up failure."},
547 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_ENG_LOAD_DIMK_ERR,
548 "DIMK failed to derive device identity."},
549 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_SEC_UKV_CLEAN_ERR,
550 "Key Vault clean up failure."},
551 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_EFUSE_ZERO_ERR,
552 "No security efuse allowed."},
553 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_ENG_LOAD_ERR,
554 "efuse policy check failed."},
555 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_PERST_INIT_FAIL,
556 "Peristent data initialization failure. Detected an error during configuration."
557 },
558 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_DIMK_INIT_FAIL,
559 "DIMK Initialization failure. Detected an error during configuration."},
560 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_PERST_SECONDARY_INIT_FAIL,
561 "Handoff data include CMF main and signature blocks validation failure. Detected an error during configuration."
562 },
563 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_BR_INFO_INIT_FAIL,
564 "CMF Bootrom header validation failure."},
565 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_CMF_DESC_FAIL,
566 "CMF Descriptor failure."},
567 {MBOX_CFGSTATE_MINOR_ERR_SYSINIT_DRNG_INIT_FAIL,
568 "DRNG Initialization failed."},
569 {MBOX_CFGSTATE_MINOR_ERR_UNK,
570 "Unknown error number at minor field!"}
571};
572
573#define MBOX_CFGSTAT_MINOR_ERR_MAX ARRAY_SIZE(mbox_cfgstat_minor_err)
574
575struct mbox_err_msg {
576 const char *major_err_str;
577 const char *minor_err_str;
578};
579
580static void mbox_cfgstat_to_str(int err, struct mbox_err_msg *err_msg)
581{
582 int i;
583 u32 major_err;
584 u32 minor_err;
585
586 major_err = FIELD_GET(MBOX_CFG_STATUS_MAJOR_ERR_MSK, err);
587
588 minor_err = FIELD_GET(MBOX_CFG_STATUS_MINOR_ERR_MSK, err);
589
590 if (!err_msg) {
591 printf("Invalid argument\n");
592 return;
593 }
594
595 err_msg->major_err_str = "";
596 err_msg->minor_err_str = "";
597
598 /*
599 * In the case of getting error number 0, meaning the
600 * ATF BL31 is not supporting the feature yet thus,
601 * the SMC call will return 0 at the second argument
602 * return the message to indicate that current BL31
603 * is not yet supporting feature and need to check
604 * the BL31 version.
605 */
606 if (err == 0) {
607 err_msg->major_err_str = mbox_cfgstat_major_err[err].error_name;
608 return;
609 }
610
611 /* Initialize the major error string with unknown error */
612 err_msg->major_err_str = mbox_cfgstat_major_err[0].error_name;
613
614 for (i = 0; i < MBOX_CFGSTAT_MAJOR_ERR_MAX - 1; i++) {
615 if (mbox_cfgstat_major_err[i].err_no == major_err) {
616 err_msg->major_err_str = mbox_cfgstat_major_err[i].error_name;
617 break;
618 }
619 }
620
621 /* Return configuration state if device still under config state */
622 if (major_err == MBOX_CFGSTATE_MAJOR_ERR_STATE_CONFIG)
623 return;
624
625 /* Initialize the minor error string with unknown error */
626 err_msg->minor_err_str = mbox_cfgstat_minor_err[0].error_name;
627
628 for (i = 0; i < MBOX_CFGSTAT_MINOR_ERR_MAX - 1; i++) {
629 if (mbox_cfgstat_minor_err[i].err_no == minor_err) {
630 err_msg->minor_err_str = mbox_cfgstat_minor_err[i].error_name;
631 break;
632 }
633 }
634}
635
Chee Hong Angec4c6792020-12-24 18:21:07 +0800636/*
637 * Polling the FPGA configuration status.
638 * Return 0 for success, non-zero for error.
639 */
Boon Khai Ng483a1bb2025-01-17 14:33:31 +0800640static int reconfig_status_polling_resp(uint32_t *error_status)
Chee Hong Angec4c6792020-12-24 18:21:07 +0800641{
642 int ret;
Boon Khai Ng483a1bb2025-01-17 14:33:31 +0800643 u64 res_buf[3];
Chee Hong Angec4c6792020-12-24 18:21:07 +0800644 unsigned long start = get_timer(0);
645
646 while (1) {
647 ret = invoke_smc(INTEL_SIP_SMC_FPGA_CONFIG_ISDONE, NULL, 0,
Boon Khai Ng483a1bb2025-01-17 14:33:31 +0800648 res_buf, ARRAY_SIZE(res_buf));
649
650 if (error_status)
651 *error_status = (uint32_t)res_buf[0];
Chee Hong Angec4c6792020-12-24 18:21:07 +0800652
653 if (!ret)
654 return 0; /* configuration success */
655
656 if (ret != INTEL_SIP_SMC_STATUS_BUSY)
657 return ret;
658
659 if (get_timer(start) > RECONFIG_STATUS_POLL_RESP_TIMEOUT_MS)
660 return -ETIMEDOUT; /* time out */
661
662 puts(".");
663 udelay(RECONFIG_STATUS_INTERVAL_DELAY_US);
Stefan Roese80877fa2022-09-02 14:10:46 +0200664 schedule();
Chee Hong Angec4c6792020-12-24 18:21:07 +0800665 }
666
667 return -ETIMEDOUT;
668}
669
670static int send_bitstream(const void *rbf_data, size_t rbf_size)
671{
672 int i;
673 u64 res_buf[3];
674 u64 args[2];
675 u32 xfer_count = 0;
676 int ret, wr_ret = 0, retry = 0;
677 size_t buf_size = (rbf_size > BITSTREAM_CHUNK_SIZE) ?
678 BITSTREAM_CHUNK_SIZE : rbf_size;
679
680 while (rbf_size || xfer_count) {
681 if (!wr_ret && rbf_size) {
682 args[0] = (u64)rbf_data;
683 args[1] = buf_size;
684 wr_ret = invoke_smc(INTEL_SIP_SMC_FPGA_CONFIG_WRITE,
685 args, 2, NULL, 0);
686
687 debug("wr_ret = %d, rbf_data = %p, buf_size = %08lx\n",
688 wr_ret, rbf_data, buf_size);
689
690 if (wr_ret)
691 continue;
692
693 rbf_size -= buf_size;
694 rbf_data += buf_size;
695
696 if (buf_size >= rbf_size)
697 buf_size = rbf_size;
698
699 xfer_count++;
700 puts(".");
701 } else {
702 ret = invoke_smc(
703 INTEL_SIP_SMC_FPGA_CONFIG_COMPLETED_WRITE,
704 NULL, 0, res_buf, ARRAY_SIZE(res_buf));
705 if (!ret) {
706 for (i = 0; i < ARRAY_SIZE(res_buf); i++) {
707 if (!res_buf[i])
708 break;
709 xfer_count--;
710 wr_ret = 0;
711 retry = 0;
712 }
713 } else if (ret !=
714 INTEL_SIP_SMC_STATUS_BUSY)
715 return ret;
716 else if (!xfer_count)
717 return INTEL_SIP_SMC_STATUS_ERROR;
718
719 if (++retry >= RECONFIG_STATUS_POLL_RETRY_MAX)
720 return -ETIMEDOUT;
721
722 udelay(20000);
723 }
Stefan Roese80877fa2022-09-02 14:10:46 +0200724 schedule();
Chee Hong Angec4c6792020-12-24 18:21:07 +0800725 }
726
727 return 0;
728}
729
730/*
731 * This is the interface used by FPGA driver.
732 * Return 0 for success, non-zero for error.
733 */
734int intel_sdm_mb_load(Altera_desc *desc, const void *rbf_data, size_t rbf_size)
735{
736 int ret;
737 u64 arg = 1;
Boon Khai Ng483a1bb2025-01-17 14:33:31 +0800738 u32 err_status = 0;
739 u64 res_buf[3];
740 struct mbox_err_msg err_msg;
Chee Hong Angec4c6792020-12-24 18:21:07 +0800741
742 debug("Invoking FPGA_CONFIG_START...\n");
743
Naresh Kumar Ravulapalli94c40c02025-05-05 18:28:51 -0700744 flush_dcache_range((unsigned long)rbf_data, (unsigned long)(rbf_data + rbf_size));
745
Chee Hong Angec4c6792020-12-24 18:21:07 +0800746 ret = invoke_smc(INTEL_SIP_SMC_FPGA_CONFIG_START, &arg, 1, NULL, 0);
747
748 if (ret) {
Boon Khai Ng483a1bb2025-01-17 14:33:31 +0800749 puts("U-Boot SMC: Failure in RECONFIG mailbox command!\n");
Chee Hong Angec4c6792020-12-24 18:21:07 +0800750 return ret;
751 }
752
753 ret = send_bitstream(rbf_data, rbf_size);
754 if (ret) {
Boon Khai Ng483a1bb2025-01-17 14:33:31 +0800755 puts("\nU-Boot SMC: Error sending bitstream!\n");
756 ret = invoke_smc(INTEL_SIP_SMC_FPGA_CONFIG_ISDONE, NULL, 0,
757 res_buf, ARRAY_SIZE(res_buf));
758
759 err_status = res_buf[0];
760 mbox_cfgstat_to_str(err_status, &err_msg);
761 printf("SDM: Config status: (0x%x)\nSDM Err: %s\n%s\n", err_status,
762 err_msg.major_err_str, err_msg.minor_err_str);
763
Chee Hong Angec4c6792020-12-24 18:21:07 +0800764 return ret;
765 }
766
767 /* Make sure we don't send MBOX_RECONFIG_STATUS too fast */
768 udelay(RECONFIG_STATUS_INTERVAL_DELAY_US);
769
Boon Khai Ng483a1bb2025-01-17 14:33:31 +0800770 debug("U-Boot SMC: Polling with MBOX_RECONFIG_STATUS...\n");
771 ret = reconfig_status_polling_resp(&err_status);
Chee Hong Angec4c6792020-12-24 18:21:07 +0800772 if (ret) {
Boon Khai Ng483a1bb2025-01-17 14:33:31 +0800773 printf("\nU-Boot SMC: FPGA reconfiguration failed!\n");
774 mbox_cfgstat_to_str(err_status, &err_msg);
775 printf("SDM: Config status: (0x%x)\nSDM Err:%s\n%s\n", err_status,
776 err_msg.major_err_str, err_msg.minor_err_str);
777
Chee Hong Angec4c6792020-12-24 18:21:07 +0800778 return ret;
779 }
780
781 puts("FPGA reconfiguration OK!\n");
782
783 return ret;
784}
785
786#else
787
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -0800788static const struct mbox_cfgstat_state {
789 int err_no;
790 const char *error_name;
791} mbox_cfgstat_state[] = {
792 {MBOX_CFGSTAT_STATE_IDLE, "FPGA in idle mode."},
793 {MBOX_CFGSTAT_STATE_CONFIG, "FPGA in config mode."},
794 {MBOX_CFGSTAT_STATE_FAILACK, "Acknowledgment failed!"},
795 {MBOX_CFGSTAT_STATE_ERROR_INVALID, "Invalid bitstream!"},
796 {MBOX_CFGSTAT_STATE_ERROR_CORRUPT, "Corrupted bitstream!"},
797 {MBOX_CFGSTAT_STATE_ERROR_AUTH, "Authentication failed!"},
798 {MBOX_CFGSTAT_STATE_ERROR_CORE_IO, "I/O error!"},
799 {MBOX_CFGSTAT_STATE_ERROR_HARDWARE, "Hardware error!"},
800 {MBOX_CFGSTAT_STATE_ERROR_FAKE, "Fake error!"},
801 {MBOX_CFGSTAT_STATE_ERROR_BOOT_INFO, "Error in boot info!"},
802 {MBOX_CFGSTAT_STATE_ERROR_QSPI_ERROR, "Error in QSPI!"},
803 {MBOX_RESP_ERROR, "Mailbox general error!"},
804 {-ETIMEDOUT, "I/O timeout error"},
805 {-1, "Unknown error!"}
806};
807
808#define MBOX_CFGSTAT_MAX ARRAY_SIZE(mbox_cfgstat_state)
809
810static const char *mbox_cfgstat_to_str(int err)
811{
812 int i;
813
814 for (i = 0; i < MBOX_CFGSTAT_MAX - 1; i++) {
815 if (mbox_cfgstat_state[i].err_no == err)
816 return mbox_cfgstat_state[i].error_name;
817 }
818
819 return mbox_cfgstat_state[MBOX_CFGSTAT_MAX - 1].error_name;
820}
821
822/*
823 * Add the ongoing transaction's command ID into pending list and return
824 * the command ID for next transfer.
825 */
826static u8 add_transfer(u32 *xfer_pending_list, size_t list_size, u8 id)
827{
828 int i;
829
830 for (i = 0; i < list_size; i++) {
831 if (xfer_pending_list[i])
832 continue;
833 xfer_pending_list[i] = id;
834 debug("ID(%d) added to transaction pending list\n", id);
835 /*
836 * Increment command ID for next transaction.
837 * Valid command ID (4 bits) is from 1 to 15.
838 */
839 id = (id % 15) + 1;
840 break;
841 }
842
843 return id;
844}
845
846/*
847 * Check whether response ID match the command ID in the transfer
848 * pending list. If a match is found in the transfer pending list,
849 * it clears the transfer pending list and return the matched
850 * command ID.
851 */
852static int get_and_clr_transfer(u32 *xfer_pending_list, size_t list_size,
853 u8 id)
854{
855 int i;
856
857 for (i = 0; i < list_size; i++) {
858 if (id != xfer_pending_list[i])
859 continue;
860 xfer_pending_list[i] = 0;
861 return id;
862 }
863
864 return 0;
865}
866
867/*
868 * Polling the FPGA configuration status.
869 * Return 0 for success, non-zero for error.
870 */
871static int reconfig_status_polling_resp(void)
872{
873 int ret;
874 unsigned long start = get_timer(0);
875
876 while (1) {
877 ret = mbox_get_fpga_config_status(MBOX_RECONFIG_STATUS);
878 if (!ret)
879 return 0; /* configuration success */
880
881 if (ret != MBOX_CFGSTAT_STATE_CONFIG)
882 return ret;
883
884 if (get_timer(start) > RECONFIG_STATUS_POLL_RESP_TIMEOUT_MS)
885 break; /* time out */
886
887 puts(".");
888 udelay(RECONFIG_STATUS_INTERVAL_DELAY_US);
Stefan Roese80877fa2022-09-02 14:10:46 +0200889 schedule();
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -0800890 }
891
892 return -ETIMEDOUT;
893}
894
895static u32 get_resp_hdr(u32 *r_index, u32 *w_index, u32 *resp_count,
896 u32 *resp_buf, u32 buf_size, u32 client_id)
897{
898 u32 buf[MBOX_RESP_BUFFER_SIZE];
899 u32 mbox_hdr;
900 u32 resp_len;
901 u32 hdr_len;
902 u32 i;
903
904 if (*resp_count < buf_size) {
905 u32 rcv_len_max = buf_size - *resp_count;
906
907 if (rcv_len_max > MBOX_RESP_BUFFER_SIZE)
908 rcv_len_max = MBOX_RESP_BUFFER_SIZE;
909 resp_len = mbox_rcv_resp(buf, rcv_len_max);
910
911 for (i = 0; i < resp_len; i++) {
912 resp_buf[(*w_index)++] = buf[i];
913 *w_index %= buf_size;
914 (*resp_count)++;
915 }
916 }
917
918 /* No response in buffer */
919 if (*resp_count == 0)
920 return 0;
921
922 mbox_hdr = resp_buf[*r_index];
923
924 hdr_len = MBOX_RESP_LEN_GET(mbox_hdr);
925
926 /* Insufficient header length to return a mailbox header */
927 if ((*resp_count - 1) < hdr_len)
928 return 0;
929
930 *r_index += (hdr_len + 1);
931 *r_index %= buf_size;
932 *resp_count -= (hdr_len + 1);
933
934 /* Make sure response belongs to us */
935 if (MBOX_RESP_CLIENT_GET(mbox_hdr) != client_id)
936 return 0;
937
938 return mbox_hdr;
939}
940
941/* Send bit stream data to SDM via RECONFIG_DATA mailbox command */
942static int send_reconfig_data(const void *rbf_data, size_t rbf_size,
943 u32 xfer_max, u32 buf_size_max)
944{
945 u32 response_buffer[MBOX_RESP_BUFFER_SIZE];
946 u32 xfer_pending[MBOX_RESP_BUFFER_SIZE];
947 u32 resp_rindex = 0;
948 u32 resp_windex = 0;
949 u32 resp_count = 0;
950 u32 xfer_count = 0;
Ang, Chee Hongc4192f72019-02-17 20:07:50 -0800951 int resp_err = 0;
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -0800952 u8 cmd_id = 1;
953 u32 args[3];
954 int ret;
955
956 debug("SDM xfer_max = %d\n", xfer_max);
957 debug("SDM buf_size_max = %x\n\n", buf_size_max);
958
959 memset(xfer_pending, 0, sizeof(xfer_pending));
960
961 while (rbf_size || xfer_count) {
962 if (!resp_err && rbf_size && xfer_count < xfer_max) {
963 args[0] = MBOX_ARG_DESC_COUNT(1);
964 args[1] = (u64)rbf_data;
965 if (rbf_size >= buf_size_max) {
966 args[2] = buf_size_max;
967 rbf_size -= buf_size_max;
968 rbf_data += buf_size_max;
969 } else {
970 args[2] = (u64)rbf_size;
971 rbf_size = 0;
972 }
973
Ang, Chee Hongc4192f72019-02-17 20:07:50 -0800974 resp_err = mbox_send_cmd_only(cmd_id, MBOX_RECONFIG_DATA,
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -0800975 MBOX_CMD_INDIRECT, 3, args);
Ang, Chee Hongc4192f72019-02-17 20:07:50 -0800976 if (!resp_err) {
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -0800977 xfer_count++;
978 cmd_id = add_transfer(xfer_pending,
979 MBOX_RESP_BUFFER_SIZE,
980 cmd_id);
981 }
982 puts(".");
983 } else {
984 u32 resp_hdr = get_resp_hdr(&resp_rindex, &resp_windex,
985 &resp_count,
986 response_buffer,
987 MBOX_RESP_BUFFER_SIZE,
988 MBOX_CLIENT_ID_UBOOT);
989
990 /*
991 * If no valid response header found or
992 * non-zero length from RECONFIG_DATA
993 */
994 if (!resp_hdr || MBOX_RESP_LEN_GET(resp_hdr))
995 continue;
996
997 /* Check for response's status */
998 if (!resp_err) {
Ang, Chee Hongc4192f72019-02-17 20:07:50 -0800999 resp_err = MBOX_RESP_ERR_GET(resp_hdr);
1000 debug("Response error code: %08x\n", resp_err);
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -08001001 }
1002
1003 ret = get_and_clr_transfer(xfer_pending,
1004 MBOX_RESP_BUFFER_SIZE,
1005 MBOX_RESP_ID_GET(resp_hdr));
1006 if (ret) {
1007 /* Claim and reuse the ID */
1008 cmd_id = (u8)ret;
1009 xfer_count--;
1010 }
1011
1012 if (resp_err && !xfer_count)
Ang, Chee Hongc4192f72019-02-17 20:07:50 -08001013 return resp_err;
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -08001014 }
Stefan Roese80877fa2022-09-02 14:10:46 +02001015 schedule();
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -08001016 }
1017
1018 return 0;
1019}
1020
1021/*
1022 * This is the interface used by FPGA driver.
1023 * Return 0 for success, non-zero for error.
1024 */
Chee Hong Ang14192452020-08-07 11:50:03 +08001025int intel_sdm_mb_load(Altera_desc *desc, const void *rbf_data, size_t rbf_size)
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -08001026{
1027 int ret;
1028 u32 resp_len = 2;
1029 u32 resp_buf[2];
1030
Naresh Kumar Ravulapalli94c40c02025-05-05 18:28:51 -07001031 flush_dcache_range((unsigned long)rbf_data, (unsigned long)(rbf_data + rbf_size));
1032
Ang, Chee Hongdcc3bb62018-12-19 18:35:14 -08001033 debug("Sending MBOX_RECONFIG...\n");
1034 ret = mbox_send_cmd(MBOX_ID_UBOOT, MBOX_RECONFIG, MBOX_CMD_DIRECT, 0,
1035 NULL, 0, &resp_len, resp_buf);
1036 if (ret) {
1037 puts("Failure in RECONFIG mailbox command!\n");
1038 return ret;
1039 }
1040
1041 ret = send_reconfig_data(rbf_data, rbf_size, resp_buf[0], resp_buf[1]);
1042 if (ret) {
1043 printf("RECONFIG_DATA error: %08x, %s\n", ret,
1044 mbox_cfgstat_to_str(ret));
1045 return ret;
1046 }
1047
1048 /* Make sure we don't send MBOX_RECONFIG_STATUS too fast */
1049 udelay(RECONFIG_STATUS_INTERVAL_DELAY_US);
1050
1051 debug("Polling with MBOX_RECONFIG_STATUS...\n");
1052 ret = reconfig_status_polling_resp();
1053 if (ret) {
1054 printf("RECONFIG_STATUS Error: %08x, %s\n", ret,
1055 mbox_cfgstat_to_str(ret));
1056 return ret;
1057 }
1058
1059 puts("FPGA reconfiguration OK!\n");
1060
1061 return ret;
1062}
Chee Hong Angec4c6792020-12-24 18:21:07 +08001063#endif