blob: d53e8deb54b9b343126fe4f826fe8970567d8191 [file] [log] [blame]
Hadi Asyrafi616da772019-06-27 11:34:03 +08001/*
Abdul Halim, Muhammad Hadi Asyrafi461f5442020-07-03 13:22:09 +08002 * Copyright (c) 2019-2022, ARM Limited and Contributors. All rights reserved.
Hadi Asyrafi616da772019-06-27 11:34:03 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8#include <common/debug.h>
9#include <common/runtime_svc.h>
Hadi Asyrafi67942302019-10-22 13:28:51 +080010#include <lib/mmio.h>
Hadi Asyrafi616da772019-06-27 11:34:03 +080011#include <tools_share/uuid.h>
12
Hadi Asyrafi6f8a2b22019-10-23 18:34:14 +080013#include "socfpga_mailbox.h"
Hadi Asyrafi36a9f302019-12-24 10:42:52 +080014#include "socfpga_reset_manager.h"
Hadi Asyrafiab1132f2019-10-22 10:31:45 +080015#include "socfpga_sip_svc.h"
Hadi Asyrafi616da772019-06-27 11:34:03 +080016
Hadi Asyrafi616da772019-06-27 11:34:03 +080017
18/* Total buffer the driver can hold */
19#define FPGA_CONFIG_BUFFER_SIZE 4
20
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +080021static int current_block, current_buffer;
22static int read_block, max_blocks, is_partial_reconfig;
23static uint32_t send_id, rcv_id;
24static uint32_t bytes_per_block, blocks_submitted;
Hadi Asyrafi616da772019-06-27 11:34:03 +080025
Hadi Asyrafi616da772019-06-27 11:34:03 +080026
27/* SiP Service UUID */
28DEFINE_SVC_UUID2(intl_svc_uid,
29 0xa85273b0, 0xe85a, 0x4862, 0xa6, 0x2a,
30 0xfa, 0x88, 0x88, 0x17, 0x68, 0x81);
31
Hadi Asyraficee6aa92019-12-17 15:25:04 +080032static uint64_t socfpga_sip_handler(uint32_t smc_fid,
Hadi Asyrafi616da772019-06-27 11:34:03 +080033 uint64_t x1,
34 uint64_t x2,
35 uint64_t x3,
36 uint64_t x4,
37 void *cookie,
38 void *handle,
39 uint64_t flags)
40{
41 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
42 SMC_RET1(handle, SMC_UNK);
43}
44
45struct fpga_config_info fpga_config_buffers[FPGA_CONFIG_BUFFER_SIZE];
46
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080047static int intel_fpga_sdm_write_buffer(struct fpga_config_info *buffer)
Hadi Asyrafi616da772019-06-27 11:34:03 +080048{
Abdul Halim, Muhammad Hadi Asyrafid84bfef2020-02-25 16:28:10 +080049 uint32_t args[3];
Hadi Asyrafi616da772019-06-27 11:34:03 +080050
51 while (max_blocks > 0 && buffer->size > buffer->size_written) {
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080052 args[0] = (1<<8);
53 args[1] = buffer->addr + buffer->size_written;
54 if (buffer->size - buffer->size_written <= bytes_per_block) {
Hadi Asyrafi616da772019-06-27 11:34:03 +080055 args[2] = buffer->size - buffer->size_written;
Hadi Asyrafi616da772019-06-27 11:34:03 +080056 current_buffer++;
57 current_buffer %= FPGA_CONFIG_BUFFER_SIZE;
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080058 } else
Hadi Asyrafi616da772019-06-27 11:34:03 +080059 args[2] = bytes_per_block;
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080060
61 buffer->size_written += args[2];
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +080062 mailbox_send_cmd_async(&send_id, MBOX_RECONFIG_DATA, args,
Abdul Halim, Muhammad Hadi Asyrafi118ab212020-10-15 15:27:18 +080063 3U, CMD_INDIRECT);
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080064
65 buffer->subblocks_sent++;
Hadi Asyrafi616da772019-06-27 11:34:03 +080066 max_blocks--;
67 }
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080068
69 return !max_blocks;
Hadi Asyrafi616da772019-06-27 11:34:03 +080070}
71
72static int intel_fpga_sdm_write_all(void)
73{
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080074 for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++)
75 if (intel_fpga_sdm_write_buffer(
76 &fpga_config_buffers[current_buffer]))
77 break;
Hadi Asyrafi616da772019-06-27 11:34:03 +080078 return 0;
79}
80
Hadi Asyrafi0c6dae22019-12-17 23:33:39 +080081static uint32_t intel_mailbox_fpga_config_isdone(uint32_t query_type)
Hadi Asyrafi616da772019-06-27 11:34:03 +080082{
Hadi Asyrafi0c6dae22019-12-17 23:33:39 +080083 uint32_t ret;
84
85 if (query_type == 1)
Sieu Mun Tang24682662022-02-19 21:49:48 +080086 ret = intel_mailbox_get_config_status(MBOX_CONFIG_STATUS, false);
Hadi Asyrafi0c6dae22019-12-17 23:33:39 +080087 else
Sieu Mun Tang24682662022-02-19 21:49:48 +080088 ret = intel_mailbox_get_config_status(MBOX_RECONFIG_STATUS, true);
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080089
90 if (ret) {
91 if (ret == MBOX_CFGSTAT_STATE_CONFIG)
92 return INTEL_SIP_SMC_STATUS_BUSY;
93 else
94 return INTEL_SIP_SMC_STATUS_ERROR;
95 }
96
Hadi Asyrafi36a9f302019-12-24 10:42:52 +080097 if (query_type != 1) {
98 /* full reconfiguration */
99 if (!is_partial_reconfig)
100 socfpga_bridges_enable(); /* Enable bridge */
101 }
102
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800103 return INTEL_SIP_SMC_STATUS_OK;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800104}
105
106static int mark_last_buffer_xfer_completed(uint32_t *buffer_addr_completed)
107{
108 int i;
109
110 for (i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
111 if (fpga_config_buffers[i].block_number == current_block) {
112 fpga_config_buffers[i].subblocks_sent--;
113 if (fpga_config_buffers[i].subblocks_sent == 0
114 && fpga_config_buffers[i].size <=
115 fpga_config_buffers[i].size_written) {
116 fpga_config_buffers[i].write_requested = 0;
117 current_block++;
118 *buffer_addr_completed =
119 fpga_config_buffers[i].addr;
120 return 0;
121 }
122 }
123 }
124
125 return -1;
126}
127
Hadi Asyraficee6aa92019-12-17 15:25:04 +0800128static int intel_fpga_config_completed_write(uint32_t *completed_addr,
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800129 uint32_t *count, uint32_t *job_id)
Hadi Asyrafi616da772019-06-27 11:34:03 +0800130{
Hadi Asyrafi616da772019-06-27 11:34:03 +0800131 uint32_t resp[5];
Sieu Mun Tang24682662022-02-19 21:49:48 +0800132 unsigned int resp_len = ARRAY_SIZE(resp);
133 int status = INTEL_SIP_SMC_STATUS_OK;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800134 int all_completed = 1;
Sieu Mun Tang24682662022-02-19 21:49:48 +0800135 *count = 0;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800136
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800137 while (*count < 3) {
Hadi Asyrafi616da772019-06-27 11:34:03 +0800138
Sieu Mun Tang24682662022-02-19 21:49:48 +0800139 status = mailbox_read_response(job_id,
140 resp, &resp_len);
Hadi Asyrafi616da772019-06-27 11:34:03 +0800141
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800142 if (resp_len < 0)
143 break;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800144
Hadi Asyrafi616da772019-06-27 11:34:03 +0800145 max_blocks++;
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800146
Hadi Asyrafi616da772019-06-27 11:34:03 +0800147 if (mark_last_buffer_xfer_completed(
148 &completed_addr[*count]) == 0)
149 *count = *count + 1;
150 else
151 break;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800152 }
153
154 if (*count <= 0) {
155 if (resp_len != MBOX_NO_RESPONSE &&
156 resp_len != MBOX_TIMEOUT && resp_len != 0) {
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800157 mailbox_clear_response();
Hadi Asyrafi616da772019-06-27 11:34:03 +0800158 return INTEL_SIP_SMC_STATUS_ERROR;
159 }
160
161 *count = 0;
162 }
163
164 intel_fpga_sdm_write_all();
165
166 if (*count > 0)
167 status = INTEL_SIP_SMC_STATUS_OK;
168 else if (*count == 0)
169 status = INTEL_SIP_SMC_STATUS_BUSY;
170
171 for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
172 if (fpga_config_buffers[i].write_requested != 0) {
173 all_completed = 0;
174 break;
175 }
176 }
177
178 if (all_completed == 1)
179 return INTEL_SIP_SMC_STATUS_OK;
180
181 return status;
182}
183
Hadi Asyraficee6aa92019-12-17 15:25:04 +0800184static int intel_fpga_config_start(uint32_t config_type)
Hadi Asyrafi616da772019-06-27 11:34:03 +0800185{
Sieu Mun Tang24682662022-02-19 21:49:48 +0800186 uint32_t argument = 0x1;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800187 uint32_t response[3];
188 int status = 0;
Sieu Mun Tang24682662022-02-19 21:49:48 +0800189 unsigned int size = 0;
190 unsigned int resp_len = ARRAY_SIZE(response);
Hadi Asyrafi616da772019-06-27 11:34:03 +0800191
Hadi Asyrafi36a9f302019-12-24 10:42:52 +0800192 is_partial_reconfig = config_type;
193
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800194 mailbox_clear_response();
195
Sieu Mun Tang24682662022-02-19 21:49:48 +0800196 mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_CANCEL, NULL, 0U,
197 CMD_CASUAL, NULL, NULL);
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800198
Sieu Mun Tang24682662022-02-19 21:49:48 +0800199 status = mailbox_send_cmd(MBOX_JOB_ID, MBOX_RECONFIG, &argument, size,
200 CMD_CASUAL, response, &resp_len);
Hadi Asyrafi616da772019-06-27 11:34:03 +0800201
202 if (status < 0)
203 return status;
204
205 max_blocks = response[0];
206 bytes_per_block = response[1];
207
208 for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
209 fpga_config_buffers[i].size = 0;
210 fpga_config_buffers[i].size_written = 0;
211 fpga_config_buffers[i].addr = 0;
212 fpga_config_buffers[i].write_requested = 0;
213 fpga_config_buffers[i].block_number = 0;
214 fpga_config_buffers[i].subblocks_sent = 0;
215 }
216
217 blocks_submitted = 0;
218 current_block = 0;
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800219 read_block = 0;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800220 current_buffer = 0;
221
Hadi Asyrafi36a9f302019-12-24 10:42:52 +0800222 /* full reconfiguration */
223 if (!is_partial_reconfig) {
224 /* Disable bridge */
225 socfpga_bridges_disable();
226 }
227
Hadi Asyrafi616da772019-06-27 11:34:03 +0800228 return 0;
229}
230
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800231static bool is_fpga_config_buffer_full(void)
232{
233 for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++)
234 if (!fpga_config_buffers[i].write_requested)
235 return false;
236 return true;
237}
238
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800239bool is_address_in_ddr_range(uint64_t addr, uint64_t size)
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800240{
Abdul Halim, Muhammad Hadi Asyrafi461f5442020-07-03 13:22:09 +0800241 if (!addr && !size) {
242 return true;
243 }
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800244 if (size > (UINT64_MAX - addr))
245 return false;
Abdul Halim, Muhammad Hadi Asyrafie59b9992020-02-11 20:17:05 +0800246 if (addr < BL31_LIMIT)
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800247 return false;
248 if (addr + size > DRAM_BASE + DRAM_SIZE)
249 return false;
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800250
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800251 return true;
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800252}
Hadi Asyrafi616da772019-06-27 11:34:03 +0800253
Hadi Asyraficee6aa92019-12-17 15:25:04 +0800254static uint32_t intel_fpga_config_write(uint64_t mem, uint64_t size)
Hadi Asyrafi616da772019-06-27 11:34:03 +0800255{
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800256 int i;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800257
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800258 intel_fpga_sdm_write_all();
Hadi Asyrafi616da772019-06-27 11:34:03 +0800259
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800260 if (!is_address_in_ddr_range(mem, size) ||
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800261 is_fpga_config_buffer_full())
262 return INTEL_SIP_SMC_STATUS_REJECTED;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800263
264 for (i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800265 int j = (i + current_buffer) % FPGA_CONFIG_BUFFER_SIZE;
266
267 if (!fpga_config_buffers[j].write_requested) {
268 fpga_config_buffers[j].addr = mem;
269 fpga_config_buffers[j].size = size;
270 fpga_config_buffers[j].size_written = 0;
271 fpga_config_buffers[j].write_requested = 1;
272 fpga_config_buffers[j].block_number =
Hadi Asyrafi616da772019-06-27 11:34:03 +0800273 blocks_submitted++;
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800274 fpga_config_buffers[j].subblocks_sent = 0;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800275 break;
276 }
277 }
278
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800279 if (is_fpga_config_buffer_full())
280 return INTEL_SIP_SMC_STATUS_BUSY;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800281
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800282 return INTEL_SIP_SMC_STATUS_OK;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800283}
284
Hadi Asyrafi67942302019-10-22 13:28:51 +0800285static int is_out_of_sec_range(uint64_t reg_addr)
286{
287 switch (reg_addr) {
288 case(0xF8011100): /* ECCCTRL1 */
289 case(0xF8011104): /* ECCCTRL2 */
290 case(0xF8011110): /* ERRINTEN */
291 case(0xF8011114): /* ERRINTENS */
292 case(0xF8011118): /* ERRINTENR */
293 case(0xF801111C): /* INTMODE */
294 case(0xF8011120): /* INTSTAT */
295 case(0xF8011124): /* DIAGINTTEST */
296 case(0xF801112C): /* DERRADDRA */
297 case(0xFFD12028): /* SDMMCGRP_CTRL */
298 case(0xFFD12044): /* EMAC0 */
299 case(0xFFD12048): /* EMAC1 */
300 case(0xFFD1204C): /* EMAC2 */
301 case(0xFFD12090): /* ECC_INT_MASK_VALUE */
302 case(0xFFD12094): /* ECC_INT_MASK_SET */
303 case(0xFFD12098): /* ECC_INT_MASK_CLEAR */
304 case(0xFFD1209C): /* ECC_INTSTATUS_SERR */
305 case(0xFFD120A0): /* ECC_INTSTATUS_DERR */
306 case(0xFFD120C0): /* NOC_TIMEOUT */
307 case(0xFFD120C4): /* NOC_IDLEREQ_SET */
308 case(0xFFD120C8): /* NOC_IDLEREQ_CLR */
309 case(0xFFD120D0): /* NOC_IDLEACK */
310 case(0xFFD120D4): /* NOC_IDLESTATUS */
311 case(0xFFD12200): /* BOOT_SCRATCH_COLD0 */
312 case(0xFFD12204): /* BOOT_SCRATCH_COLD1 */
313 case(0xFFD12220): /* BOOT_SCRATCH_COLD8 */
314 case(0xFFD12224): /* BOOT_SCRATCH_COLD9 */
315 return 0;
316
317 default:
318 break;
319 }
320
321 return -1;
322}
323
324/* Secure register access */
325uint32_t intel_secure_reg_read(uint64_t reg_addr, uint32_t *retval)
326{
327 if (is_out_of_sec_range(reg_addr))
328 return INTEL_SIP_SMC_STATUS_ERROR;
329
330 *retval = mmio_read_32(reg_addr);
331
332 return INTEL_SIP_SMC_STATUS_OK;
333}
334
335uint32_t intel_secure_reg_write(uint64_t reg_addr, uint32_t val,
336 uint32_t *retval)
337{
338 if (is_out_of_sec_range(reg_addr))
339 return INTEL_SIP_SMC_STATUS_ERROR;
340
341 mmio_write_32(reg_addr, val);
342
343 return intel_secure_reg_read(reg_addr, retval);
344}
345
346uint32_t intel_secure_reg_update(uint64_t reg_addr, uint32_t mask,
347 uint32_t val, uint32_t *retval)
348{
349 if (!intel_secure_reg_read(reg_addr, retval)) {
350 *retval &= ~mask;
Siew Chin Lima0763152021-07-10 00:55:35 +0800351 *retval |= val & mask;
Hadi Asyrafi67942302019-10-22 13:28:51 +0800352 return intel_secure_reg_write(reg_addr, *retval, retval);
353 }
354
355 return INTEL_SIP_SMC_STATUS_ERROR;
356}
357
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800358/* Intel Remote System Update (RSU) services */
359uint64_t intel_rsu_update_address;
360
Abdul Halim, Muhammad Hadi Asyrafi118ab212020-10-15 15:27:18 +0800361static uint32_t intel_rsu_status(uint64_t *respbuf, unsigned int respbuf_sz)
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800362{
363 if (mailbox_rsu_status((uint32_t *)respbuf, respbuf_sz) < 0)
Abdul Halim, Muhammad Hadi Asyrafi25f623e2020-02-27 10:23:48 +0800364 return INTEL_SIP_SMC_RSU_ERROR;
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800365
366 return INTEL_SIP_SMC_STATUS_OK;
367}
368
369static uint32_t intel_rsu_update(uint64_t update_address)
370{
371 intel_rsu_update_address = update_address;
372 return INTEL_SIP_SMC_STATUS_OK;
373}
374
Abdul Halim, Muhammad Hadi Asyrafid84bfef2020-02-25 16:28:10 +0800375static uint32_t intel_rsu_notify(uint32_t execution_stage)
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800376{
Abdul Halim, Muhammad Hadi Asyrafie59b9992020-02-11 20:17:05 +0800377 if (mailbox_hps_stage_notify(execution_stage) < 0)
Abdul Halim, Muhammad Hadi Asyrafi25f623e2020-02-27 10:23:48 +0800378 return INTEL_SIP_SMC_RSU_ERROR;
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800379
380 return INTEL_SIP_SMC_STATUS_OK;
381}
382
383static uint32_t intel_rsu_retry_counter(uint32_t *respbuf, uint32_t respbuf_sz,
384 uint32_t *ret_stat)
385{
386 if (mailbox_rsu_status((uint32_t *)respbuf, respbuf_sz) < 0)
Abdul Halim, Muhammad Hadi Asyrafi25f623e2020-02-27 10:23:48 +0800387 return INTEL_SIP_SMC_RSU_ERROR;
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800388
389 *ret_stat = respbuf[8];
390 return INTEL_SIP_SMC_STATUS_OK;
391}
392
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800393/* Mailbox services */
Sieu Mun Tang24682662022-02-19 21:49:48 +0800394static uint32_t intel_mbox_send_cmd(uint32_t cmd, uint32_t *args,
395 unsigned int len,
396 uint32_t urgent, uint32_t *response,
397 unsigned int resp_len, int *mbox_status,
398 unsigned int *len_in_resp)
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800399{
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800400 *len_in_resp = 0;
401 *mbox_status = 0;
402
403 if (!is_address_in_ddr_range((uint64_t)args, sizeof(uint32_t) * len))
404 return INTEL_SIP_SMC_STATUS_REJECTED;
405
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800406 int status = mailbox_send_cmd(MBOX_JOB_ID, cmd, args, len, urgent,
Sieu Mun Tang24682662022-02-19 21:49:48 +0800407 response, &resp_len);
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800408
409 if (status < 0) {
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800410 *mbox_status = -status;
411 return INTEL_SIP_SMC_STATUS_ERROR;
412 }
413
414 *mbox_status = 0;
Sieu Mun Tang24682662022-02-19 21:49:48 +0800415 *len_in_resp = resp_len;
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800416 return INTEL_SIP_SMC_STATUS_OK;
417}
418
Hadi Asyrafi616da772019-06-27 11:34:03 +0800419/*
420 * This function is responsible for handling all SiP calls from the NS world
421 */
422
423uintptr_t sip_smc_handler(uint32_t smc_fid,
424 u_register_t x1,
425 u_register_t x2,
426 u_register_t x3,
427 u_register_t x4,
428 void *cookie,
429 void *handle,
430 u_register_t flags)
431{
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800432 uint32_t retval = 0;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800433 uint32_t status = INTEL_SIP_SMC_STATUS_OK;
434 uint32_t completed_addr[3];
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800435 uint64_t rsu_respbuf[9];
Sieu Mun Tang24682662022-02-19 21:49:48 +0800436 int mbox_status;
437 unsigned int len_in_resp;
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800438 u_register_t x5, x6;
Abdul Halim, Muhammad Hadi Asyrafib45f15e2020-05-14 15:32:43 +0800439
Hadi Asyrafi616da772019-06-27 11:34:03 +0800440 switch (smc_fid) {
441 case SIP_SVC_UID:
442 /* Return UID to the caller */
443 SMC_UUID_RET(handle, intl_svc_uid);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800444
Hadi Asyrafi616da772019-06-27 11:34:03 +0800445 case INTEL_SIP_SMC_FPGA_CONFIG_ISDONE:
Hadi Asyrafi0c6dae22019-12-17 23:33:39 +0800446 status = intel_mailbox_fpga_config_isdone(x1);
Hadi Asyrafi616da772019-06-27 11:34:03 +0800447 SMC_RET4(handle, status, 0, 0, 0);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800448
Hadi Asyrafi616da772019-06-27 11:34:03 +0800449 case INTEL_SIP_SMC_FPGA_CONFIG_GET_MEM:
450 SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK,
451 INTEL_SIP_SMC_FPGA_CONFIG_ADDR,
452 INTEL_SIP_SMC_FPGA_CONFIG_SIZE -
453 INTEL_SIP_SMC_FPGA_CONFIG_ADDR);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800454
Hadi Asyrafi616da772019-06-27 11:34:03 +0800455 case INTEL_SIP_SMC_FPGA_CONFIG_START:
456 status = intel_fpga_config_start(x1);
457 SMC_RET4(handle, status, 0, 0, 0);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800458
Hadi Asyrafi616da772019-06-27 11:34:03 +0800459 case INTEL_SIP_SMC_FPGA_CONFIG_WRITE:
460 status = intel_fpga_config_write(x1, x2);
461 SMC_RET4(handle, status, 0, 0, 0);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800462
Hadi Asyrafi616da772019-06-27 11:34:03 +0800463 case INTEL_SIP_SMC_FPGA_CONFIG_COMPLETED_WRITE:
464 status = intel_fpga_config_completed_write(completed_addr,
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800465 &retval, &rcv_id);
466 switch (retval) {
Hadi Asyrafi616da772019-06-27 11:34:03 +0800467 case 1:
468 SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK,
469 completed_addr[0], 0, 0);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800470
Hadi Asyrafi616da772019-06-27 11:34:03 +0800471 case 2:
472 SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK,
473 completed_addr[0],
474 completed_addr[1], 0);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800475
Hadi Asyrafi616da772019-06-27 11:34:03 +0800476 case 3:
477 SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK,
478 completed_addr[0],
479 completed_addr[1],
480 completed_addr[2]);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800481
Hadi Asyrafi616da772019-06-27 11:34:03 +0800482 case 0:
483 SMC_RET4(handle, status, 0, 0, 0);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800484
Hadi Asyrafi616da772019-06-27 11:34:03 +0800485 default:
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800486 mailbox_clear_response();
Hadi Asyrafi616da772019-06-27 11:34:03 +0800487 SMC_RET1(handle, INTEL_SIP_SMC_STATUS_ERROR);
488 }
Hadi Asyrafi67942302019-10-22 13:28:51 +0800489
490 case INTEL_SIP_SMC_REG_READ:
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800491 status = intel_secure_reg_read(x1, &retval);
492 SMC_RET3(handle, status, retval, x1);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800493
494 case INTEL_SIP_SMC_REG_WRITE:
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800495 status = intel_secure_reg_write(x1, (uint32_t)x2, &retval);
496 SMC_RET3(handle, status, retval, x1);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800497
498 case INTEL_SIP_SMC_REG_UPDATE:
499 status = intel_secure_reg_update(x1, (uint32_t)x2,
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800500 (uint32_t)x3, &retval);
501 SMC_RET3(handle, status, retval, x1);
Hadi Asyrafi616da772019-06-27 11:34:03 +0800502
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800503 case INTEL_SIP_SMC_RSU_STATUS:
504 status = intel_rsu_status(rsu_respbuf,
505 ARRAY_SIZE(rsu_respbuf));
506 if (status) {
507 SMC_RET1(handle, status);
508 } else {
509 SMC_RET4(handle, rsu_respbuf[0], rsu_respbuf[1],
510 rsu_respbuf[2], rsu_respbuf[3]);
511 }
512
513 case INTEL_SIP_SMC_RSU_UPDATE:
514 status = intel_rsu_update(x1);
515 SMC_RET1(handle, status);
516
517 case INTEL_SIP_SMC_RSU_NOTIFY:
518 status = intel_rsu_notify(x1);
519 SMC_RET1(handle, status);
520
521 case INTEL_SIP_SMC_RSU_RETRY_COUNTER:
522 status = intel_rsu_retry_counter((uint32_t *)rsu_respbuf,
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800523 ARRAY_SIZE(rsu_respbuf), &retval);
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800524 if (status) {
525 SMC_RET1(handle, status);
526 } else {
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800527 SMC_RET2(handle, status, retval);
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800528 }
529
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800530 case INTEL_SIP_SMC_MBOX_SEND_CMD:
531 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
532 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
Abdul Halim, Muhammad Hadi Asyrafid84bfef2020-02-25 16:28:10 +0800533 status = intel_mbox_send_cmd(x1, (uint32_t *)x2, x3, x4,
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800534 (uint32_t *)x5, x6, &mbox_status,
535 &len_in_resp);
Sieu Mun Tangf02f0cb2022-02-19 20:36:41 +0800536 SMC_RET3(handle, status, mbox_status, len_in_resp);
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800537
Hadi Asyrafi616da772019-06-27 11:34:03 +0800538 default:
539 return socfpga_sip_handler(smc_fid, x1, x2, x3, x4,
540 cookie, handle, flags);
541 }
542}
543
544DECLARE_RT_SVC(
Hadi Asyrafi4d9f3952019-10-23 17:35:32 +0800545 socfpga_sip_svc,
Hadi Asyrafi616da772019-06-27 11:34:03 +0800546 OEN_SIP_START,
547 OEN_SIP_END,
548 SMC_TYPE_FAST,
549 NULL,
550 sip_smc_handler
551);
552
553DECLARE_RT_SVC(
Hadi Asyrafi4d9f3952019-10-23 17:35:32 +0800554 socfpga_sip_svc_std,
Hadi Asyrafi616da772019-06-27 11:34:03 +0800555 OEN_SIP_START,
556 OEN_SIP_END,
557 SMC_TYPE_YIELD,
558 NULL,
559 sip_smc_handler
560);