xref: /rk3399_ARM-atf/plat/intel/soc/common/socfpga_sip_svc.c (revision 93a5b97ec9e97207769db18ae34886e6b8bf2ea4)
1 /*
2  * Copyright (c) 2019-2022, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 #include <common/debug.h>
9 #include <common/runtime_svc.h>
10 #include <lib/mmio.h>
11 #include <tools_share/uuid.h>
12 
13 #include "socfpga_fcs.h"
14 #include "socfpga_mailbox.h"
15 #include "socfpga_reset_manager.h"
16 #include "socfpga_sip_svc.h"
17 
18 
19 /* Total buffer the driver can hold */
20 #define FPGA_CONFIG_BUFFER_SIZE 4
21 
22 static int current_block, current_buffer;
23 static int read_block, max_blocks;
24 static uint32_t send_id, rcv_id;
25 static uint32_t bytes_per_block, blocks_submitted;
26 static bool bridge_disable;
27 
28 /* RSU static variables */
29 static uint32_t rsu_dcmf_ver[4] = {0};
30 
31 /* RSU Max Retry */
32 static uint32_t rsu_max_retry;
33 static uint16_t rsu_dcmf_stat[4] = {0};
34 
35 /*  SiP Service UUID */
36 DEFINE_SVC_UUID2(intl_svc_uid,
37 		0xa85273b0, 0xe85a, 0x4862, 0xa6, 0x2a,
38 		0xfa, 0x88, 0x88, 0x17, 0x68, 0x81);
39 
40 static uint64_t socfpga_sip_handler(uint32_t smc_fid,
41 				   uint64_t x1,
42 				   uint64_t x2,
43 				   uint64_t x3,
44 				   uint64_t x4,
45 				   void *cookie,
46 				   void *handle,
47 				   uint64_t flags)
48 {
49 	ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
50 	SMC_RET1(handle, SMC_UNK);
51 }
52 
53 struct fpga_config_info fpga_config_buffers[FPGA_CONFIG_BUFFER_SIZE];
54 
55 static int intel_fpga_sdm_write_buffer(struct fpga_config_info *buffer)
56 {
57 	uint32_t args[3];
58 
59 	while (max_blocks > 0 && buffer->size > buffer->size_written) {
60 		args[0] = (1<<8);
61 		args[1] = buffer->addr + buffer->size_written;
62 		if (buffer->size - buffer->size_written <= bytes_per_block) {
63 			args[2] = buffer->size - buffer->size_written;
64 			current_buffer++;
65 			current_buffer %= FPGA_CONFIG_BUFFER_SIZE;
66 		} else
67 			args[2] = bytes_per_block;
68 
69 		buffer->size_written += args[2];
70 		mailbox_send_cmd_async(&send_id, MBOX_RECONFIG_DATA, args,
71 					3U, CMD_INDIRECT);
72 
73 		buffer->subblocks_sent++;
74 		max_blocks--;
75 	}
76 
77 	return !max_blocks;
78 }
79 
80 static int intel_fpga_sdm_write_all(void)
81 {
82 	for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++)
83 		if (intel_fpga_sdm_write_buffer(
84 			&fpga_config_buffers[current_buffer]))
85 			break;
86 	return 0;
87 }
88 
89 static uint32_t intel_mailbox_fpga_config_isdone(uint32_t query_type)
90 {
91 	uint32_t ret;
92 
93 	if (query_type == 1)
94 		ret = intel_mailbox_get_config_status(MBOX_CONFIG_STATUS, false);
95 	else
96 		ret = intel_mailbox_get_config_status(MBOX_RECONFIG_STATUS, true);
97 
98 	if (ret != 0U) {
99 		if (ret == MBOX_CFGSTAT_STATE_CONFIG)
100 			return INTEL_SIP_SMC_STATUS_BUSY;
101 		else
102 			return INTEL_SIP_SMC_STATUS_ERROR;
103 	}
104 
105 	if (bridge_disable) {
106 		socfpga_bridges_enable();	/* Enable bridge */
107 		bridge_disable = false;
108 	}
109 
110 	return INTEL_SIP_SMC_STATUS_OK;
111 }
112 
113 static int mark_last_buffer_xfer_completed(uint32_t *buffer_addr_completed)
114 {
115 	int i;
116 
117 	for (i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
118 		if (fpga_config_buffers[i].block_number == current_block) {
119 			fpga_config_buffers[i].subblocks_sent--;
120 			if (fpga_config_buffers[i].subblocks_sent == 0
121 			&& fpga_config_buffers[i].size <=
122 			fpga_config_buffers[i].size_written) {
123 				fpga_config_buffers[i].write_requested = 0;
124 				current_block++;
125 				*buffer_addr_completed =
126 					fpga_config_buffers[i].addr;
127 				return 0;
128 			}
129 		}
130 	}
131 
132 	return -1;
133 }
134 
135 static int intel_fpga_config_completed_write(uint32_t *completed_addr,
136 					uint32_t *count, uint32_t *job_id)
137 {
138 	uint32_t resp[5];
139 	unsigned int resp_len = ARRAY_SIZE(resp);
140 	int status = INTEL_SIP_SMC_STATUS_OK;
141 	int all_completed = 1;
142 	*count = 0;
143 
144 	while (*count < 3) {
145 
146 		status = mailbox_read_response(job_id,
147 				resp, &resp_len);
148 
149 		if (status < 0) {
150 			break;
151 		}
152 
153 		max_blocks++;
154 
155 		if (mark_last_buffer_xfer_completed(
156 			&completed_addr[*count]) == 0) {
157 			*count = *count + 1;
158 		} else {
159 			break;
160 		}
161 	}
162 
163 	if (*count <= 0) {
164 		if (status != MBOX_NO_RESPONSE &&
165 			status != MBOX_TIMEOUT && resp_len != 0) {
166 			mailbox_clear_response();
167 			return INTEL_SIP_SMC_STATUS_ERROR;
168 		}
169 
170 		*count = 0;
171 	}
172 
173 	intel_fpga_sdm_write_all();
174 
175 	if (*count > 0)
176 		status = INTEL_SIP_SMC_STATUS_OK;
177 	else if (*count == 0)
178 		status = INTEL_SIP_SMC_STATUS_BUSY;
179 
180 	for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
181 		if (fpga_config_buffers[i].write_requested != 0) {
182 			all_completed = 0;
183 			break;
184 		}
185 	}
186 
187 	if (all_completed == 1)
188 		return INTEL_SIP_SMC_STATUS_OK;
189 
190 	return status;
191 }
192 
193 static int intel_fpga_config_start(uint32_t flag)
194 {
195 	uint32_t argument = 0x1;
196 	uint32_t response[3];
197 	int status = 0;
198 	unsigned int size = 0;
199 	unsigned int resp_len = ARRAY_SIZE(response);
200 
201 	if (!CONFIG_TEST_FLAG(flag, PARTIAL_CONFIG)) {
202 		bridge_disable = true;
203 	}
204 
205 	if (CONFIG_TEST_FLAG(flag, AUTHENTICATION)) {
206 		size = 1;
207 		bridge_disable = false;
208 	}
209 
210 	mailbox_clear_response();
211 
212 	mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_CANCEL, NULL, 0U,
213 			CMD_CASUAL, NULL, NULL);
214 
215 	status = mailbox_send_cmd(MBOX_JOB_ID, MBOX_RECONFIG, &argument, size,
216 			CMD_CASUAL, response, &resp_len);
217 
218 	if (status < 0) {
219 		bridge_disable = false;
220 		return INTEL_SIP_SMC_STATUS_ERROR;
221 	}
222 
223 	max_blocks = response[0];
224 	bytes_per_block = response[1];
225 
226 	for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
227 		fpga_config_buffers[i].size = 0;
228 		fpga_config_buffers[i].size_written = 0;
229 		fpga_config_buffers[i].addr = 0;
230 		fpga_config_buffers[i].write_requested = 0;
231 		fpga_config_buffers[i].block_number = 0;
232 		fpga_config_buffers[i].subblocks_sent = 0;
233 	}
234 
235 	blocks_submitted = 0;
236 	current_block = 0;
237 	read_block = 0;
238 	current_buffer = 0;
239 
240 	/* Disable bridge on full reconfiguration */
241 	if (bridge_disable) {
242 		socfpga_bridges_disable();
243 	}
244 
245 	return INTEL_SIP_SMC_STATUS_OK;
246 }
247 
248 static bool is_fpga_config_buffer_full(void)
249 {
250 	for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++)
251 		if (!fpga_config_buffers[i].write_requested)
252 			return false;
253 	return true;
254 }
255 
256 bool is_address_in_ddr_range(uint64_t addr, uint64_t size)
257 {
258 	if (!addr && !size) {
259 		return true;
260 	}
261 	if (size > (UINT64_MAX - addr))
262 		return false;
263 	if (addr < BL31_LIMIT)
264 		return false;
265 	if (addr + size > DRAM_BASE + DRAM_SIZE)
266 		return false;
267 
268 	return true;
269 }
270 
271 static uint32_t intel_fpga_config_write(uint64_t mem, uint64_t size)
272 {
273 	int i;
274 
275 	intel_fpga_sdm_write_all();
276 
277 	if (!is_address_in_ddr_range(mem, size) ||
278 		is_fpga_config_buffer_full()) {
279 		return INTEL_SIP_SMC_STATUS_REJECTED;
280 	}
281 
282 	for (i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
283 		int j = (i + current_buffer) % FPGA_CONFIG_BUFFER_SIZE;
284 
285 		if (!fpga_config_buffers[j].write_requested) {
286 			fpga_config_buffers[j].addr = mem;
287 			fpga_config_buffers[j].size = size;
288 			fpga_config_buffers[j].size_written = 0;
289 			fpga_config_buffers[j].write_requested = 1;
290 			fpga_config_buffers[j].block_number =
291 				blocks_submitted++;
292 			fpga_config_buffers[j].subblocks_sent = 0;
293 			break;
294 		}
295 	}
296 
297 	if (is_fpga_config_buffer_full()) {
298 		return INTEL_SIP_SMC_STATUS_BUSY;
299 	}
300 
301 	return INTEL_SIP_SMC_STATUS_OK;
302 }
303 
304 static int is_out_of_sec_range(uint64_t reg_addr)
305 {
306 #if DEBUG
307 	return 0;
308 #endif
309 
310 	switch (reg_addr) {
311 	case(0xF8011100):	/* ECCCTRL1 */
312 	case(0xF8011104):	/* ECCCTRL2 */
313 	case(0xF8011110):	/* ERRINTEN */
314 	case(0xF8011114):	/* ERRINTENS */
315 	case(0xF8011118):	/* ERRINTENR */
316 	case(0xF801111C):	/* INTMODE */
317 	case(0xF8011120):	/* INTSTAT */
318 	case(0xF8011124):	/* DIAGINTTEST */
319 	case(0xF801112C):	/* DERRADDRA */
320 	case(0xFFD12028):	/* SDMMCGRP_CTRL */
321 	case(0xFFD12044):	/* EMAC0 */
322 	case(0xFFD12048):	/* EMAC1 */
323 	case(0xFFD1204C):	/* EMAC2 */
324 	case(0xFFD12090):	/* ECC_INT_MASK_VALUE */
325 	case(0xFFD12094):	/* ECC_INT_MASK_SET */
326 	case(0xFFD12098):	/* ECC_INT_MASK_CLEAR */
327 	case(0xFFD1209C):	/* ECC_INTSTATUS_SERR */
328 	case(0xFFD120A0):	/* ECC_INTSTATUS_DERR */
329 	case(0xFFD120C0):	/* NOC_TIMEOUT */
330 	case(0xFFD120C4):	/* NOC_IDLEREQ_SET */
331 	case(0xFFD120C8):	/* NOC_IDLEREQ_CLR */
332 	case(0xFFD120D0):	/* NOC_IDLEACK */
333 	case(0xFFD120D4):	/* NOC_IDLESTATUS */
334 	case(0xFFD12200):	/* BOOT_SCRATCH_COLD0 */
335 	case(0xFFD12204):	/* BOOT_SCRATCH_COLD1 */
336 	case(0xFFD12220):	/* BOOT_SCRATCH_COLD8 */
337 	case(0xFFD12224):	/* BOOT_SCRATCH_COLD9 */
338 		return 0;
339 
340 	default:
341 		break;
342 	}
343 
344 	return -1;
345 }
346 
347 /* Secure register access */
348 uint32_t intel_secure_reg_read(uint64_t reg_addr, uint32_t *retval)
349 {
350 	if (is_out_of_sec_range(reg_addr))
351 		return INTEL_SIP_SMC_STATUS_ERROR;
352 
353 	*retval = mmio_read_32(reg_addr);
354 
355 	return INTEL_SIP_SMC_STATUS_OK;
356 }
357 
358 uint32_t intel_secure_reg_write(uint64_t reg_addr, uint32_t val,
359 				uint32_t *retval)
360 {
361 	if (is_out_of_sec_range(reg_addr))
362 		return INTEL_SIP_SMC_STATUS_ERROR;
363 
364 	mmio_write_32(reg_addr, val);
365 
366 	return intel_secure_reg_read(reg_addr, retval);
367 }
368 
369 uint32_t intel_secure_reg_update(uint64_t reg_addr, uint32_t mask,
370 				 uint32_t val, uint32_t *retval)
371 {
372 	if (!intel_secure_reg_read(reg_addr, retval)) {
373 		*retval &= ~mask;
374 		*retval |= val & mask;
375 		return intel_secure_reg_write(reg_addr, *retval, retval);
376 	}
377 
378 	return INTEL_SIP_SMC_STATUS_ERROR;
379 }
380 
381 /* Intel Remote System Update (RSU) services */
382 uint64_t intel_rsu_update_address;
383 
384 static uint32_t intel_rsu_status(uint64_t *respbuf, unsigned int respbuf_sz)
385 {
386 	if (mailbox_rsu_status((uint32_t *)respbuf, respbuf_sz) < 0)
387 		return INTEL_SIP_SMC_RSU_ERROR;
388 
389 	return INTEL_SIP_SMC_STATUS_OK;
390 }
391 
392 static uint32_t intel_rsu_update(uint64_t update_address)
393 {
394 	intel_rsu_update_address = update_address;
395 	return INTEL_SIP_SMC_STATUS_OK;
396 }
397 
398 static uint32_t intel_rsu_notify(uint32_t execution_stage)
399 {
400 	if (mailbox_hps_stage_notify(execution_stage) < 0)
401 		return INTEL_SIP_SMC_RSU_ERROR;
402 
403 	return INTEL_SIP_SMC_STATUS_OK;
404 }
405 
406 static uint32_t intel_rsu_retry_counter(uint32_t *respbuf, uint32_t respbuf_sz,
407 					uint32_t *ret_stat)
408 {
409 	if (mailbox_rsu_status((uint32_t *)respbuf, respbuf_sz) < 0)
410 		return INTEL_SIP_SMC_RSU_ERROR;
411 
412 	*ret_stat = respbuf[8];
413 	return INTEL_SIP_SMC_STATUS_OK;
414 }
415 
416 static uint32_t intel_rsu_copy_dcmf_version(uint64_t dcmf_ver_1_0,
417 					    uint64_t dcmf_ver_3_2)
418 {
419 	rsu_dcmf_ver[0] = dcmf_ver_1_0;
420 	rsu_dcmf_ver[1] = dcmf_ver_1_0 >> 32;
421 	rsu_dcmf_ver[2] = dcmf_ver_3_2;
422 	rsu_dcmf_ver[3] = dcmf_ver_3_2 >> 32;
423 
424 	return INTEL_SIP_SMC_STATUS_OK;
425 }
426 
427 static uint32_t intel_rsu_copy_dcmf_status(uint64_t dcmf_stat)
428 {
429 	rsu_dcmf_stat[0] = 0xFFFF & (dcmf_stat >> (0 * 16));
430 	rsu_dcmf_stat[1] = 0xFFFF & (dcmf_stat >> (1 * 16));
431 	rsu_dcmf_stat[2] = 0xFFFF & (dcmf_stat >> (2 * 16));
432 	rsu_dcmf_stat[3] = 0xFFFF & (dcmf_stat >> (3 * 16));
433 
434 	return INTEL_SIP_SMC_STATUS_OK;
435 }
436 
437 /* Mailbox services */
438 static uint32_t intel_smc_fw_version(uint32_t *fw_version)
439 {
440 	int status;
441 	unsigned int resp_len = CONFIG_STATUS_WORD_SIZE;
442 	uint32_t resp_data[CONFIG_STATUS_WORD_SIZE] = {0U};
443 
444 	status = mailbox_send_cmd(MBOX_JOB_ID, MBOX_CONFIG_STATUS, NULL, 0U,
445 			CMD_CASUAL, resp_data, &resp_len);
446 
447 	if (status < 0) {
448 		return INTEL_SIP_SMC_STATUS_ERROR;
449 	}
450 
451 	if (resp_len <= CONFIG_STATUS_FW_VER_OFFSET) {
452 		return INTEL_SIP_SMC_STATUS_ERROR;
453 	}
454 
455 	*fw_version = resp_data[CONFIG_STATUS_FW_VER_OFFSET] & CONFIG_STATUS_FW_VER_MASK;
456 
457 	return INTEL_SIP_SMC_STATUS_OK;
458 }
459 
460 static uint32_t intel_mbox_send_cmd(uint32_t cmd, uint32_t *args,
461 				unsigned int len,
462 				uint32_t urgent, uint32_t *response,
463 				unsigned int resp_len, int *mbox_status,
464 				unsigned int *len_in_resp)
465 {
466 	*len_in_resp = 0;
467 	*mbox_status = 0;
468 
469 	if (!is_address_in_ddr_range((uint64_t)args, sizeof(uint32_t) * len))
470 		return INTEL_SIP_SMC_STATUS_REJECTED;
471 
472 	int status = mailbox_send_cmd(MBOX_JOB_ID, cmd, args, len, urgent,
473 				      response, &resp_len);
474 
475 	if (status < 0) {
476 		*mbox_status = -status;
477 		return INTEL_SIP_SMC_STATUS_ERROR;
478 	}
479 
480 	*mbox_status = 0;
481 	*len_in_resp = resp_len;
482 	return INTEL_SIP_SMC_STATUS_OK;
483 }
484 
485 static int intel_smc_get_usercode(uint32_t *user_code)
486 {
487 	int status;
488 	unsigned int resp_len = sizeof(user_code) / MBOX_WORD_BYTE;
489 
490 	status = mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_GET_USERCODE, NULL,
491 				0U, CMD_CASUAL, user_code, &resp_len);
492 
493 	if (status < 0) {
494 		return INTEL_SIP_SMC_STATUS_ERROR;
495 	}
496 
497 	return INTEL_SIP_SMC_STATUS_OK;
498 }
499 
500 /* Miscellaneous HPS services */
501 static uint32_t intel_hps_set_bridges(uint64_t enable)
502 {
503 	if (enable != 0U) {
504 		socfpga_bridges_enable();
505 	} else {
506 		socfpga_bridges_disable();
507 	}
508 
509 	return INTEL_SIP_SMC_STATUS_OK;
510 }
511 
512 /*
513  * This function is responsible for handling all SiP calls from the NS world
514  */
515 
516 uintptr_t sip_smc_handler(uint32_t smc_fid,
517 			 u_register_t x1,
518 			 u_register_t x2,
519 			 u_register_t x3,
520 			 u_register_t x4,
521 			 void *cookie,
522 			 void *handle,
523 			 u_register_t flags)
524 {
525 	uint32_t retval = 0;
526 	uint32_t mbox_error = 0;
527 	uint32_t completed_addr[3];
528 	uint64_t retval64, rsu_respbuf[9];
529 	int status = INTEL_SIP_SMC_STATUS_OK;
530 	int mbox_status;
531 	unsigned int len_in_resp;
532 	u_register_t x5, x6;
533 
534 	switch (smc_fid) {
535 	case SIP_SVC_UID:
536 		/* Return UID to the caller */
537 		SMC_UUID_RET(handle, intl_svc_uid);
538 
539 	case INTEL_SIP_SMC_FPGA_CONFIG_ISDONE:
540 		status = intel_mailbox_fpga_config_isdone(x1);
541 		SMC_RET4(handle, status, 0, 0, 0);
542 
543 	case INTEL_SIP_SMC_FPGA_CONFIG_GET_MEM:
544 		SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK,
545 			INTEL_SIP_SMC_FPGA_CONFIG_ADDR,
546 			INTEL_SIP_SMC_FPGA_CONFIG_SIZE -
547 				INTEL_SIP_SMC_FPGA_CONFIG_ADDR);
548 
549 	case INTEL_SIP_SMC_FPGA_CONFIG_START:
550 		status = intel_fpga_config_start(x1);
551 		SMC_RET4(handle, status, 0, 0, 0);
552 
553 	case INTEL_SIP_SMC_FPGA_CONFIG_WRITE:
554 		status = intel_fpga_config_write(x1, x2);
555 		SMC_RET4(handle, status, 0, 0, 0);
556 
557 	case INTEL_SIP_SMC_FPGA_CONFIG_COMPLETED_WRITE:
558 		status = intel_fpga_config_completed_write(completed_addr,
559 							&retval, &rcv_id);
560 		switch (retval) {
561 		case 1:
562 			SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK,
563 				completed_addr[0], 0, 0);
564 
565 		case 2:
566 			SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK,
567 				completed_addr[0],
568 				completed_addr[1], 0);
569 
570 		case 3:
571 			SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK,
572 				completed_addr[0],
573 				completed_addr[1],
574 				completed_addr[2]);
575 
576 		case 0:
577 			SMC_RET4(handle, status, 0, 0, 0);
578 
579 		default:
580 			mailbox_clear_response();
581 			SMC_RET1(handle, INTEL_SIP_SMC_STATUS_ERROR);
582 		}
583 
584 	case INTEL_SIP_SMC_REG_READ:
585 		status = intel_secure_reg_read(x1, &retval);
586 		SMC_RET3(handle, status, retval, x1);
587 
588 	case INTEL_SIP_SMC_REG_WRITE:
589 		status = intel_secure_reg_write(x1, (uint32_t)x2, &retval);
590 		SMC_RET3(handle, status, retval, x1);
591 
592 	case INTEL_SIP_SMC_REG_UPDATE:
593 		status = intel_secure_reg_update(x1, (uint32_t)x2,
594 						 (uint32_t)x3, &retval);
595 		SMC_RET3(handle, status, retval, x1);
596 
597 	case INTEL_SIP_SMC_RSU_STATUS:
598 		status = intel_rsu_status(rsu_respbuf,
599 					ARRAY_SIZE(rsu_respbuf));
600 		if (status) {
601 			SMC_RET1(handle, status);
602 		} else {
603 			SMC_RET4(handle, rsu_respbuf[0], rsu_respbuf[1],
604 					rsu_respbuf[2], rsu_respbuf[3]);
605 		}
606 
607 	case INTEL_SIP_SMC_RSU_UPDATE:
608 		status = intel_rsu_update(x1);
609 		SMC_RET1(handle, status);
610 
611 	case INTEL_SIP_SMC_RSU_NOTIFY:
612 		status = intel_rsu_notify(x1);
613 		SMC_RET1(handle, status);
614 
615 	case INTEL_SIP_SMC_RSU_RETRY_COUNTER:
616 		status = intel_rsu_retry_counter((uint32_t *)rsu_respbuf,
617 						ARRAY_SIZE(rsu_respbuf), &retval);
618 		if (status) {
619 			SMC_RET1(handle, status);
620 		} else {
621 			SMC_RET2(handle, status, retval);
622 		}
623 
624 	case INTEL_SIP_SMC_RSU_DCMF_VERSION:
625 		SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK,
626 			 ((uint64_t)rsu_dcmf_ver[1] << 32) | rsu_dcmf_ver[0],
627 			 ((uint64_t)rsu_dcmf_ver[3] << 32) | rsu_dcmf_ver[2]);
628 
629 	case INTEL_SIP_SMC_RSU_COPY_DCMF_VERSION:
630 		status = intel_rsu_copy_dcmf_version(x1, x2);
631 		SMC_RET1(handle, status);
632 
633 	case INTEL_SIP_SMC_RSU_DCMF_STATUS:
634 		SMC_RET2(handle, INTEL_SIP_SMC_STATUS_OK,
635 			 ((uint64_t)rsu_dcmf_stat[3] << 48) |
636 			 ((uint64_t)rsu_dcmf_stat[2] << 32) |
637 			 ((uint64_t)rsu_dcmf_stat[1] << 16) |
638 			 rsu_dcmf_stat[0]);
639 
640 	case INTEL_SIP_SMC_RSU_COPY_DCMF_STATUS:
641 		status = intel_rsu_copy_dcmf_status(x1);
642 		SMC_RET1(handle, status);
643 
644 	case INTEL_SIP_SMC_RSU_MAX_RETRY:
645 		SMC_RET2(handle, INTEL_SIP_SMC_STATUS_OK, rsu_max_retry);
646 
647 	case INTEL_SIP_SMC_RSU_COPY_MAX_RETRY:
648 		rsu_max_retry = x1;
649 		SMC_RET1(handle, INTEL_SIP_SMC_STATUS_OK);
650 
651 	case INTEL_SIP_SMC_ECC_DBE:
652 		status = intel_ecc_dbe_notification(x1);
653 		SMC_RET1(handle, status);
654 
655 	case INTEL_SIP_SMC_FIRMWARE_VERSION:
656 		status = intel_smc_fw_version(&retval);
657 		SMC_RET2(handle, status, retval);
658 
659 	case INTEL_SIP_SMC_MBOX_SEND_CMD:
660 		x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
661 		x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
662 		status = intel_mbox_send_cmd(x1, (uint32_t *)x2, x3, x4,
663 					     (uint32_t *)x5, x6, &mbox_status,
664 					     &len_in_resp);
665 		SMC_RET3(handle, status, mbox_status, len_in_resp);
666 
667 	case INTEL_SIP_SMC_GET_USERCODE:
668 		status = intel_smc_get_usercode(&retval);
669 		SMC_RET2(handle, status, retval);
670 
671 	case INTEL_SIP_SMC_GET_ROM_PATCH_SHA384:
672 		status = intel_fcs_get_rom_patch_sha384(x1, &retval64,
673 							&mbox_error);
674 		SMC_RET4(handle, status, mbox_error, x1, retval64);
675 
676 	case INTEL_SIP_SMC_SVC_VERSION:
677 		SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK,
678 					SIP_SVC_VERSION_MAJOR,
679 					SIP_SVC_VERSION_MINOR);
680 
681 	case INTEL_SIP_SMC_HPS_SET_BRIDGES:
682 		status = intel_hps_set_bridges(x1);
683 		SMC_RET1(handle, status);
684 
685 	default:
686 		return socfpga_sip_handler(smc_fid, x1, x2, x3, x4,
687 			cookie, handle, flags);
688 	}
689 }
690 
691 DECLARE_RT_SVC(
692 	socfpga_sip_svc,
693 	OEN_SIP_START,
694 	OEN_SIP_END,
695 	SMC_TYPE_FAST,
696 	NULL,
697 	sip_smc_handler
698 );
699 
700 DECLARE_RT_SVC(
701 	socfpga_sip_svc_std,
702 	OEN_SIP_START,
703 	OEN_SIP_END,
704 	SMC_TYPE_YIELD,
705 	NULL,
706 	sip_smc_handler
707 );
708