blob: a20e61c76e9c1a88874350ccb17ce410c3f25c1d [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
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +080013#include "socfpga_fcs.h"
Hadi Asyrafi6f8a2b22019-10-23 18:34:14 +080014#include "socfpga_mailbox.h"
Hadi Asyrafi36a9f302019-12-24 10:42:52 +080015#include "socfpga_reset_manager.h"
Hadi Asyrafiab1132f2019-10-22 10:31:45 +080016#include "socfpga_sip_svc.h"
Hadi Asyrafi616da772019-06-27 11:34:03 +080017
Hadi Asyrafi616da772019-06-27 11:34:03 +080018
19/* Total buffer the driver can hold */
20#define FPGA_CONFIG_BUFFER_SIZE 4
21
Sieu Mun Tangc3667602022-05-13 14:55:05 +080022static config_type request_type = NO_REQUEST;
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +080023static int current_block, current_buffer;
Abdul Halim, Muhammad Hadi Asyrafib251c332020-05-29 12:13:17 +080024static int read_block, max_blocks;
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +080025static uint32_t send_id, rcv_id;
26static uint32_t bytes_per_block, blocks_submitted;
Sieu Mun Tang54064982022-04-28 22:40:58 +080027static bool bridge_disable;
Hadi Asyrafi616da772019-06-27 11:34:03 +080028
Sieu Mun Tange6d5de92022-04-28 22:21:01 +080029/* RSU static variables */
Chee Hong Ang2cfd8ec2020-05-13 11:44:04 +080030static uint32_t rsu_dcmf_ver[4] = {0};
Sieu Mun Tange6d5de92022-04-28 22:21:01 +080031static uint16_t rsu_dcmf_stat[4] = {0};
Sieu Mun Tangc3667602022-05-13 14:55:05 +080032static uint32_t rsu_max_retry;
Hadi Asyrafi616da772019-06-27 11:34:03 +080033
34/* SiP Service UUID */
35DEFINE_SVC_UUID2(intl_svc_uid,
36 0xa85273b0, 0xe85a, 0x4862, 0xa6, 0x2a,
37 0xfa, 0x88, 0x88, 0x17, 0x68, 0x81);
38
Hadi Asyraficee6aa92019-12-17 15:25:04 +080039static uint64_t socfpga_sip_handler(uint32_t smc_fid,
Hadi Asyrafi616da772019-06-27 11:34:03 +080040 uint64_t x1,
41 uint64_t x2,
42 uint64_t x3,
43 uint64_t x4,
44 void *cookie,
45 void *handle,
46 uint64_t flags)
47{
48 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
49 SMC_RET1(handle, SMC_UNK);
50}
51
52struct fpga_config_info fpga_config_buffers[FPGA_CONFIG_BUFFER_SIZE];
53
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080054static int intel_fpga_sdm_write_buffer(struct fpga_config_info *buffer)
Hadi Asyrafi616da772019-06-27 11:34:03 +080055{
Abdul Halim, Muhammad Hadi Asyrafid84bfef2020-02-25 16:28:10 +080056 uint32_t args[3];
Hadi Asyrafi616da772019-06-27 11:34:03 +080057
58 while (max_blocks > 0 && buffer->size > buffer->size_written) {
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080059 args[0] = (1<<8);
60 args[1] = buffer->addr + buffer->size_written;
61 if (buffer->size - buffer->size_written <= bytes_per_block) {
Hadi Asyrafi616da772019-06-27 11:34:03 +080062 args[2] = buffer->size - buffer->size_written;
Hadi Asyrafi616da772019-06-27 11:34:03 +080063 current_buffer++;
64 current_buffer %= FPGA_CONFIG_BUFFER_SIZE;
Sieu Mun Tang28af1652022-05-09 10:48:53 +080065 } else {
Hadi Asyrafi616da772019-06-27 11:34:03 +080066 args[2] = bytes_per_block;
Sieu Mun Tang28af1652022-05-09 10:48:53 +080067 }
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080068
69 buffer->size_written += args[2];
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +080070 mailbox_send_cmd_async(&send_id, MBOX_RECONFIG_DATA, args,
Abdul Halim, Muhammad Hadi Asyrafi118ab212020-10-15 15:27:18 +080071 3U, CMD_INDIRECT);
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080072
73 buffer->subblocks_sent++;
Hadi Asyrafi616da772019-06-27 11:34:03 +080074 max_blocks--;
75 }
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080076
77 return !max_blocks;
Hadi Asyrafi616da772019-06-27 11:34:03 +080078}
79
80static int intel_fpga_sdm_write_all(void)
81{
Sieu Mun Tang28af1652022-05-09 10:48:53 +080082 for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080083 if (intel_fpga_sdm_write_buffer(
Sieu Mun Tang28af1652022-05-09 10:48:53 +080084 &fpga_config_buffers[current_buffer])) {
Hadi Asyrafif3a7c142019-11-12 16:29:03 +080085 break;
Sieu Mun Tang28af1652022-05-09 10:48:53 +080086 }
87 }
Hadi Asyrafi616da772019-06-27 11:34:03 +080088 return 0;
89}
90
Sieu Mun Tangc3667602022-05-13 14:55:05 +080091static uint32_t intel_mailbox_fpga_config_isdone(void)
Hadi Asyrafi616da772019-06-27 11:34:03 +080092{
Hadi Asyrafi0c6dae22019-12-17 23:33:39 +080093 uint32_t ret;
94
Sieu Mun Tangc3667602022-05-13 14:55:05 +080095 switch (request_type) {
96 case RECONFIGURATION:
97 ret = intel_mailbox_get_config_status(MBOX_RECONFIG_STATUS,
98 true);
99 break;
100 case BITSTREAM_AUTH:
101 ret = intel_mailbox_get_config_status(MBOX_RECONFIG_STATUS,
102 false);
103 break;
104 default:
105 ret = intel_mailbox_get_config_status(MBOX_CONFIG_STATUS,
106 false);
107 break;
Kris Chapline768dfa2021-06-25 11:31:52 +0100108 }
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800109
Abdul Halim, Muhammad Hadi Asyrafi959143d2020-12-29 16:49:23 +0800110 if (ret != 0U) {
Kris Chapline768dfa2021-06-25 11:31:52 +0100111 if (ret == MBOX_CFGSTAT_STATE_CONFIG) {
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800112 return INTEL_SIP_SMC_STATUS_BUSY;
Kris Chapline768dfa2021-06-25 11:31:52 +0100113 } else {
Sieu Mun Tangc3667602022-05-13 14:55:05 +0800114 request_type = NO_REQUEST;
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800115 return INTEL_SIP_SMC_STATUS_ERROR;
Kris Chapline768dfa2021-06-25 11:31:52 +0100116 }
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800117 }
118
Sieu Mun Tangc3667602022-05-13 14:55:05 +0800119 if (bridge_disable != 0U) {
Sieu Mun Tang82cf5df2022-05-05 17:07:21 +0800120 socfpga_bridges_enable(~0); /* Enable bridge */
Sieu Mun Tang54064982022-04-28 22:40:58 +0800121 bridge_disable = false;
Hadi Asyrafi36a9f302019-12-24 10:42:52 +0800122 }
Sieu Mun Tangc3667602022-05-13 14:55:05 +0800123 request_type = NO_REQUEST;
Hadi Asyrafi36a9f302019-12-24 10:42:52 +0800124
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800125 return INTEL_SIP_SMC_STATUS_OK;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800126}
127
128static int mark_last_buffer_xfer_completed(uint32_t *buffer_addr_completed)
129{
130 int i;
131
132 for (i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
133 if (fpga_config_buffers[i].block_number == current_block) {
134 fpga_config_buffers[i].subblocks_sent--;
135 if (fpga_config_buffers[i].subblocks_sent == 0
136 && fpga_config_buffers[i].size <=
137 fpga_config_buffers[i].size_written) {
138 fpga_config_buffers[i].write_requested = 0;
139 current_block++;
140 *buffer_addr_completed =
141 fpga_config_buffers[i].addr;
142 return 0;
143 }
144 }
145 }
146
147 return -1;
148}
149
Hadi Asyraficee6aa92019-12-17 15:25:04 +0800150static int intel_fpga_config_completed_write(uint32_t *completed_addr,
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800151 uint32_t *count, uint32_t *job_id)
Hadi Asyrafi616da772019-06-27 11:34:03 +0800152{
Hadi Asyrafi616da772019-06-27 11:34:03 +0800153 uint32_t resp[5];
Sieu Mun Tang24682662022-02-19 21:49:48 +0800154 unsigned int resp_len = ARRAY_SIZE(resp);
155 int status = INTEL_SIP_SMC_STATUS_OK;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800156 int all_completed = 1;
Sieu Mun Tang24682662022-02-19 21:49:48 +0800157 *count = 0;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800158
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800159 while (*count < 3) {
Hadi Asyrafi616da772019-06-27 11:34:03 +0800160
Sieu Mun Tang24682662022-02-19 21:49:48 +0800161 status = mailbox_read_response(job_id,
162 resp, &resp_len);
Hadi Asyrafi616da772019-06-27 11:34:03 +0800163
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800164 if (status < 0) {
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800165 break;
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800166 }
Hadi Asyrafi616da772019-06-27 11:34:03 +0800167
Hadi Asyrafi616da772019-06-27 11:34:03 +0800168 max_blocks++;
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800169
Hadi Asyrafi616da772019-06-27 11:34:03 +0800170 if (mark_last_buffer_xfer_completed(
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800171 &completed_addr[*count]) == 0) {
Hadi Asyrafi616da772019-06-27 11:34:03 +0800172 *count = *count + 1;
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800173 } else {
Hadi Asyrafi616da772019-06-27 11:34:03 +0800174 break;
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800175 }
Hadi Asyrafi616da772019-06-27 11:34:03 +0800176 }
177
178 if (*count <= 0) {
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800179 if (status != MBOX_NO_RESPONSE &&
180 status != MBOX_TIMEOUT && resp_len != 0) {
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800181 mailbox_clear_response();
Sieu Mun Tangc3667602022-05-13 14:55:05 +0800182 request_type = NO_REQUEST;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800183 return INTEL_SIP_SMC_STATUS_ERROR;
184 }
185
186 *count = 0;
187 }
188
189 intel_fpga_sdm_write_all();
190
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800191 if (*count > 0) {
Hadi Asyrafi616da772019-06-27 11:34:03 +0800192 status = INTEL_SIP_SMC_STATUS_OK;
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800193 } else if (*count == 0) {
Hadi Asyrafi616da772019-06-27 11:34:03 +0800194 status = INTEL_SIP_SMC_STATUS_BUSY;
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800195 }
Hadi Asyrafi616da772019-06-27 11:34:03 +0800196
197 for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
198 if (fpga_config_buffers[i].write_requested != 0) {
199 all_completed = 0;
200 break;
201 }
202 }
203
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800204 if (all_completed == 1) {
Hadi Asyrafi616da772019-06-27 11:34:03 +0800205 return INTEL_SIP_SMC_STATUS_OK;
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800206 }
Hadi Asyrafi616da772019-06-27 11:34:03 +0800207
208 return status;
209}
210
Sieu Mun Tang54064982022-04-28 22:40:58 +0800211static int intel_fpga_config_start(uint32_t flag)
Hadi Asyrafi616da772019-06-27 11:34:03 +0800212{
Sieu Mun Tang24682662022-02-19 21:49:48 +0800213 uint32_t argument = 0x1;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800214 uint32_t response[3];
215 int status = 0;
Sieu Mun Tang24682662022-02-19 21:49:48 +0800216 unsigned int size = 0;
217 unsigned int resp_len = ARRAY_SIZE(response);
Hadi Asyrafi616da772019-06-27 11:34:03 +0800218
Sieu Mun Tangc3667602022-05-13 14:55:05 +0800219 request_type = RECONFIGURATION;
220
Sieu Mun Tang54064982022-04-28 22:40:58 +0800221 if (!CONFIG_TEST_FLAG(flag, PARTIAL_CONFIG)) {
222 bridge_disable = true;
Abdul Halim, Muhammad Hadi Asyrafib251c332020-05-29 12:13:17 +0800223 }
Hadi Asyrafi36a9f302019-12-24 10:42:52 +0800224
Sieu Mun Tang54064982022-04-28 22:40:58 +0800225 if (CONFIG_TEST_FLAG(flag, AUTHENTICATION)) {
226 size = 1;
227 bridge_disable = false;
Sieu Mun Tangc3667602022-05-13 14:55:05 +0800228 request_type = BITSTREAM_AUTH;
Sieu Mun Tang54064982022-04-28 22:40:58 +0800229 }
230
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800231 mailbox_clear_response();
232
Sieu Mun Tang24682662022-02-19 21:49:48 +0800233 mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_CANCEL, NULL, 0U,
234 CMD_CASUAL, NULL, NULL);
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800235
Sieu Mun Tang24682662022-02-19 21:49:48 +0800236 status = mailbox_send_cmd(MBOX_JOB_ID, MBOX_RECONFIG, &argument, size,
237 CMD_CASUAL, response, &resp_len);
Hadi Asyrafi616da772019-06-27 11:34:03 +0800238
Abdul Halim, Muhammad Hadi Asyrafifbc39132020-11-20 11:06:00 +0800239 if (status < 0) {
Sieu Mun Tang54064982022-04-28 22:40:58 +0800240 bridge_disable = false;
Sieu Mun Tangc3667602022-05-13 14:55:05 +0800241 request_type = NO_REQUEST;
Abdul Halim, Muhammad Hadi Asyrafifbc39132020-11-20 11:06:00 +0800242 return INTEL_SIP_SMC_STATUS_ERROR;
243 }
Hadi Asyrafi616da772019-06-27 11:34:03 +0800244
245 max_blocks = response[0];
246 bytes_per_block = response[1];
247
248 for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
249 fpga_config_buffers[i].size = 0;
250 fpga_config_buffers[i].size_written = 0;
251 fpga_config_buffers[i].addr = 0;
252 fpga_config_buffers[i].write_requested = 0;
253 fpga_config_buffers[i].block_number = 0;
254 fpga_config_buffers[i].subblocks_sent = 0;
255 }
256
257 blocks_submitted = 0;
258 current_block = 0;
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800259 read_block = 0;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800260 current_buffer = 0;
261
Sieu Mun Tang54064982022-04-28 22:40:58 +0800262 /* Disable bridge on full reconfiguration */
263 if (bridge_disable) {
Sieu Mun Tang82cf5df2022-05-05 17:07:21 +0800264 socfpga_bridges_disable(~0);
Hadi Asyrafi36a9f302019-12-24 10:42:52 +0800265 }
266
Abdul Halim, Muhammad Hadi Asyrafifbc39132020-11-20 11:06:00 +0800267 return INTEL_SIP_SMC_STATUS_OK;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800268}
269
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800270static bool is_fpga_config_buffer_full(void)
271{
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800272 for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
273 if (!fpga_config_buffers[i].write_requested) {
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800274 return false;
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800275 }
276 }
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800277 return true;
278}
279
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800280bool is_address_in_ddr_range(uint64_t addr, uint64_t size)
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800281{
Abdul Halim, Muhammad Hadi Asyrafi461f5442020-07-03 13:22:09 +0800282 if (!addr && !size) {
283 return true;
284 }
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800285 if (size > (UINT64_MAX - addr)) {
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800286 return false;
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800287 }
288 if (addr < BL31_LIMIT) {
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800289 return false;
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800290 }
291 if (addr + size > DRAM_BASE + DRAM_SIZE) {
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800292 return false;
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800293 }
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800294
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800295 return true;
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800296}
Hadi Asyrafi616da772019-06-27 11:34:03 +0800297
Hadi Asyraficee6aa92019-12-17 15:25:04 +0800298static uint32_t intel_fpga_config_write(uint64_t mem, uint64_t size)
Hadi Asyrafi616da772019-06-27 11:34:03 +0800299{
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800300 int i;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800301
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800302 intel_fpga_sdm_write_all();
Hadi Asyrafi616da772019-06-27 11:34:03 +0800303
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800304 if (!is_address_in_ddr_range(mem, size) ||
Abdul Halim, Muhammad Hadi Asyrafi351e8842020-11-05 18:00:03 +0800305 is_fpga_config_buffer_full()) {
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800306 return INTEL_SIP_SMC_STATUS_REJECTED;
Abdul Halim, Muhammad Hadi Asyrafi351e8842020-11-05 18:00:03 +0800307 }
Hadi Asyrafi616da772019-06-27 11:34:03 +0800308
309 for (i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800310 int j = (i + current_buffer) % FPGA_CONFIG_BUFFER_SIZE;
311
312 if (!fpga_config_buffers[j].write_requested) {
313 fpga_config_buffers[j].addr = mem;
314 fpga_config_buffers[j].size = size;
315 fpga_config_buffers[j].size_written = 0;
316 fpga_config_buffers[j].write_requested = 1;
317 fpga_config_buffers[j].block_number =
Hadi Asyrafi616da772019-06-27 11:34:03 +0800318 blocks_submitted++;
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800319 fpga_config_buffers[j].subblocks_sent = 0;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800320 break;
321 }
322 }
323
Abdul Halim, Muhammad Hadi Asyrafi351e8842020-11-05 18:00:03 +0800324 if (is_fpga_config_buffer_full()) {
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800325 return INTEL_SIP_SMC_STATUS_BUSY;
Abdul Halim, Muhammad Hadi Asyrafi351e8842020-11-05 18:00:03 +0800326 }
Hadi Asyrafi616da772019-06-27 11:34:03 +0800327
Hadi Asyrafif3a7c142019-11-12 16:29:03 +0800328 return INTEL_SIP_SMC_STATUS_OK;
Hadi Asyrafi616da772019-06-27 11:34:03 +0800329}
330
Hadi Asyrafi67942302019-10-22 13:28:51 +0800331static int is_out_of_sec_range(uint64_t reg_addr)
332{
Siew Chin Lim869d4f52021-05-11 21:12:22 +0800333#if DEBUG
334 return 0;
335#endif
336
Hadi Asyrafi67942302019-10-22 13:28:51 +0800337 switch (reg_addr) {
338 case(0xF8011100): /* ECCCTRL1 */
339 case(0xF8011104): /* ECCCTRL2 */
340 case(0xF8011110): /* ERRINTEN */
341 case(0xF8011114): /* ERRINTENS */
342 case(0xF8011118): /* ERRINTENR */
343 case(0xF801111C): /* INTMODE */
344 case(0xF8011120): /* INTSTAT */
345 case(0xF8011124): /* DIAGINTTEST */
346 case(0xF801112C): /* DERRADDRA */
Sieu Mun Tangbd8da632022-09-28 15:58:28 +0800347 case(0xFA000000): /* SMMU SCR0 */
348 case(0xFA000004): /* SMMU SCR1 */
349 case(0xFA000400): /* SMMU NSCR0 */
350 case(0xFA004000): /* SMMU SSD0_REG */
351 case(0xFA000820): /* SMMU SMR8 */
352 case(0xFA000c20): /* SMMU SCR8 */
353 case(0xFA028000): /* SMMU CB8_SCTRL */
354 case(0xFA001020): /* SMMU CBAR8 */
355 case(0xFA028030): /* SMMU TCR_LPAE */
356 case(0xFA028020): /* SMMU CB8_TTBR0_LOW */
357 case(0xFA028024): /* SMMU CB8_PRRR_HIGH */
358 case(0xFA028038): /* SMMU CB8_PRRR_MIR0 */
359 case(0xFA02803C): /* SMMU CB8_PRRR_MIR1 */
360 case(0xFA028010): /* SMMU_CB8)TCR2 */
361 case(0xFFD080A4): /* SDM SMMU STREAM ID REG */
362 case(0xFA001820): /* SMMU_CBA2R8 */
363 case(0xFA000074): /* SMMU_STLBGSTATUS */
364 case(0xFA0287F4): /* SMMU_CB8_TLBSTATUS */
365 case(0xFA000060): /* SMMU_STLBIALL */
366 case(0xFA000070): /* SMMU_STLBGSYNC */
367 case(0xFA028618): /* CB8_TLBALL */
368 case(0xFA0287F0): /* CB8_TLBSYNC */
Hadi Asyrafi67942302019-10-22 13:28:51 +0800369 case(0xFFD12028): /* SDMMCGRP_CTRL */
370 case(0xFFD12044): /* EMAC0 */
371 case(0xFFD12048): /* EMAC1 */
372 case(0xFFD1204C): /* EMAC2 */
373 case(0xFFD12090): /* ECC_INT_MASK_VALUE */
374 case(0xFFD12094): /* ECC_INT_MASK_SET */
375 case(0xFFD12098): /* ECC_INT_MASK_CLEAR */
376 case(0xFFD1209C): /* ECC_INTSTATUS_SERR */
377 case(0xFFD120A0): /* ECC_INTSTATUS_DERR */
378 case(0xFFD120C0): /* NOC_TIMEOUT */
379 case(0xFFD120C4): /* NOC_IDLEREQ_SET */
380 case(0xFFD120C8): /* NOC_IDLEREQ_CLR */
381 case(0xFFD120D0): /* NOC_IDLEACK */
382 case(0xFFD120D4): /* NOC_IDLESTATUS */
383 case(0xFFD12200): /* BOOT_SCRATCH_COLD0 */
384 case(0xFFD12204): /* BOOT_SCRATCH_COLD1 */
385 case(0xFFD12220): /* BOOT_SCRATCH_COLD8 */
386 case(0xFFD12224): /* BOOT_SCRATCH_COLD9 */
387 return 0;
388
389 default:
390 break;
391 }
392
393 return -1;
394}
395
396/* Secure register access */
397uint32_t intel_secure_reg_read(uint64_t reg_addr, uint32_t *retval)
398{
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800399 if (is_out_of_sec_range(reg_addr)) {
Hadi Asyrafi67942302019-10-22 13:28:51 +0800400 return INTEL_SIP_SMC_STATUS_ERROR;
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800401 }
Hadi Asyrafi67942302019-10-22 13:28:51 +0800402
403 *retval = mmio_read_32(reg_addr);
404
405 return INTEL_SIP_SMC_STATUS_OK;
406}
407
408uint32_t intel_secure_reg_write(uint64_t reg_addr, uint32_t val,
409 uint32_t *retval)
410{
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800411 if (is_out_of_sec_range(reg_addr)) {
Hadi Asyrafi67942302019-10-22 13:28:51 +0800412 return INTEL_SIP_SMC_STATUS_ERROR;
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800413 }
Hadi Asyrafi67942302019-10-22 13:28:51 +0800414
415 mmio_write_32(reg_addr, val);
416
417 return intel_secure_reg_read(reg_addr, retval);
418}
419
420uint32_t intel_secure_reg_update(uint64_t reg_addr, uint32_t mask,
421 uint32_t val, uint32_t *retval)
422{
423 if (!intel_secure_reg_read(reg_addr, retval)) {
424 *retval &= ~mask;
Siew Chin Lima0763152021-07-10 00:55:35 +0800425 *retval |= val & mask;
Hadi Asyrafi67942302019-10-22 13:28:51 +0800426 return intel_secure_reg_write(reg_addr, *retval, retval);
427 }
428
429 return INTEL_SIP_SMC_STATUS_ERROR;
430}
431
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800432/* Intel Remote System Update (RSU) services */
433uint64_t intel_rsu_update_address;
434
Abdul Halim, Muhammad Hadi Asyrafi118ab212020-10-15 15:27:18 +0800435static uint32_t intel_rsu_status(uint64_t *respbuf, unsigned int respbuf_sz)
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800436{
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800437 if (mailbox_rsu_status((uint32_t *)respbuf, respbuf_sz) < 0) {
Abdul Halim, Muhammad Hadi Asyrafi25f623e2020-02-27 10:23:48 +0800438 return INTEL_SIP_SMC_RSU_ERROR;
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800439 }
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800440
441 return INTEL_SIP_SMC_STATUS_OK;
442}
443
444static uint32_t intel_rsu_update(uint64_t update_address)
445{
446 intel_rsu_update_address = update_address;
447 return INTEL_SIP_SMC_STATUS_OK;
448}
449
Abdul Halim, Muhammad Hadi Asyrafid84bfef2020-02-25 16:28:10 +0800450static uint32_t intel_rsu_notify(uint32_t execution_stage)
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800451{
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800452 if (mailbox_hps_stage_notify(execution_stage) < 0) {
Abdul Halim, Muhammad Hadi Asyrafi25f623e2020-02-27 10:23:48 +0800453 return INTEL_SIP_SMC_RSU_ERROR;
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800454 }
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800455
456 return INTEL_SIP_SMC_STATUS_OK;
457}
458
459static uint32_t intel_rsu_retry_counter(uint32_t *respbuf, uint32_t respbuf_sz,
460 uint32_t *ret_stat)
461{
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800462 if (mailbox_rsu_status((uint32_t *)respbuf, respbuf_sz) < 0) {
Abdul Halim, Muhammad Hadi Asyrafi25f623e2020-02-27 10:23:48 +0800463 return INTEL_SIP_SMC_RSU_ERROR;
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800464 }
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800465
466 *ret_stat = respbuf[8];
467 return INTEL_SIP_SMC_STATUS_OK;
468}
469
Chee Hong Ang2cfd8ec2020-05-13 11:44:04 +0800470static uint32_t intel_rsu_copy_dcmf_version(uint64_t dcmf_ver_1_0,
471 uint64_t dcmf_ver_3_2)
472{
473 rsu_dcmf_ver[0] = dcmf_ver_1_0;
474 rsu_dcmf_ver[1] = dcmf_ver_1_0 >> 32;
475 rsu_dcmf_ver[2] = dcmf_ver_3_2;
476 rsu_dcmf_ver[3] = dcmf_ver_3_2 >> 32;
477
478 return INTEL_SIP_SMC_STATUS_OK;
479}
480
Sieu Mun Tange6d5de92022-04-28 22:21:01 +0800481static uint32_t intel_rsu_copy_dcmf_status(uint64_t dcmf_stat)
482{
483 rsu_dcmf_stat[0] = 0xFFFF & (dcmf_stat >> (0 * 16));
484 rsu_dcmf_stat[1] = 0xFFFF & (dcmf_stat >> (1 * 16));
485 rsu_dcmf_stat[2] = 0xFFFF & (dcmf_stat >> (2 * 16));
486 rsu_dcmf_stat[3] = 0xFFFF & (dcmf_stat >> (3 * 16));
487
488 return INTEL_SIP_SMC_STATUS_OK;
489}
490
Kris Chapline768dfa2021-06-25 11:31:52 +0100491/* Intel HWMON services */
492static uint32_t intel_hwmon_readtemp(uint32_t chan, uint32_t *retval)
493{
Kris Chapline768dfa2021-06-25 11:31:52 +0100494 if (mailbox_hwmon_readtemp(chan, retval) < 0) {
495 return INTEL_SIP_SMC_STATUS_ERROR;
496 }
497
498 return INTEL_SIP_SMC_STATUS_OK;
499}
500
501static uint32_t intel_hwmon_readvolt(uint32_t chan, uint32_t *retval)
502{
Kris Chapline768dfa2021-06-25 11:31:52 +0100503 if (mailbox_hwmon_readvolt(chan, retval) < 0) {
504 return INTEL_SIP_SMC_STATUS_ERROR;
505 }
506
507 return INTEL_SIP_SMC_STATUS_OK;
508}
509
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800510/* Mailbox services */
Abdul Halim, Muhammad Hadi Asyrafid9006fc2021-02-05 11:50:58 +0800511static uint32_t intel_smc_fw_version(uint32_t *fw_version)
512{
Sieu Mun Tangbfda95a2022-04-27 18:54:10 +0800513 int status;
514 unsigned int resp_len = CONFIG_STATUS_WORD_SIZE;
515 uint32_t resp_data[CONFIG_STATUS_WORD_SIZE] = {0U};
516
517 status = mailbox_send_cmd(MBOX_JOB_ID, MBOX_CONFIG_STATUS, NULL, 0U,
518 CMD_CASUAL, resp_data, &resp_len);
519
520 if (status < 0) {
521 return INTEL_SIP_SMC_STATUS_ERROR;
522 }
523
524 if (resp_len <= CONFIG_STATUS_FW_VER_OFFSET) {
525 return INTEL_SIP_SMC_STATUS_ERROR;
526 }
527
528 *fw_version = resp_data[CONFIG_STATUS_FW_VER_OFFSET] & CONFIG_STATUS_FW_VER_MASK;
Abdul Halim, Muhammad Hadi Asyrafid9006fc2021-02-05 11:50:58 +0800529
530 return INTEL_SIP_SMC_STATUS_OK;
531}
532
Sieu Mun Tang24682662022-02-19 21:49:48 +0800533static uint32_t intel_mbox_send_cmd(uint32_t cmd, uint32_t *args,
Sieu Mun Tang7420c532022-05-10 23:17:04 +0800534 unsigned int len, uint32_t urgent, uint64_t response,
Sieu Mun Tang24682662022-02-19 21:49:48 +0800535 unsigned int resp_len, int *mbox_status,
536 unsigned int *len_in_resp)
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800537{
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800538 *len_in_resp = 0;
Sieu Mun Tang96bbdca2022-04-12 15:00:13 +0800539 *mbox_status = GENERIC_RESPONSE_ERROR;
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800540
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800541 if (!is_address_in_ddr_range((uint64_t)args, sizeof(uint32_t) * len)) {
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800542 return INTEL_SIP_SMC_STATUS_REJECTED;
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800543 }
Abdul Halim, Muhammad Hadi Asyrafic39a0e02020-02-06 19:18:41 +0800544
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800545 int status = mailbox_send_cmd(MBOX_JOB_ID, cmd, args, len, urgent,
Sieu Mun Tang7420c532022-05-10 23:17:04 +0800546 (uint32_t *) response, &resp_len);
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800547
548 if (status < 0) {
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800549 *mbox_status = -status;
550 return INTEL_SIP_SMC_STATUS_ERROR;
551 }
552
553 *mbox_status = 0;
Sieu Mun Tang24682662022-02-19 21:49:48 +0800554 *len_in_resp = resp_len;
Sieu Mun Tang7420c532022-05-10 23:17:04 +0800555
556 flush_dcache_range(response, resp_len * MBOX_WORD_BYTE);
557
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800558 return INTEL_SIP_SMC_STATUS_OK;
559}
560
Sieu Mun Tang2b8e0052022-04-27 18:57:29 +0800561static int intel_smc_get_usercode(uint32_t *user_code)
562{
563 int status;
564 unsigned int resp_len = sizeof(user_code) / MBOX_WORD_BYTE;
565
566 status = mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_GET_USERCODE, NULL,
567 0U, CMD_CASUAL, user_code, &resp_len);
568
569 if (status < 0) {
570 return INTEL_SIP_SMC_STATUS_ERROR;
571 }
572
573 return INTEL_SIP_SMC_STATUS_OK;
574}
575
Sieu Mun Tangfd8a8ad2022-05-07 00:50:37 +0800576uint32_t intel_smc_service_completed(uint64_t addr, uint32_t size,
577 uint32_t mode, uint32_t *job_id,
578 uint32_t *ret_size, uint32_t *mbox_error)
579{
580 int status = 0;
581 uint32_t resp_len = size / MBOX_WORD_BYTE;
582
583 if (resp_len > MBOX_DATA_MAX_LEN) {
584 return INTEL_SIP_SMC_STATUS_REJECTED;
585 }
586
587 if (!is_address_in_ddr_range(addr, size)) {
588 return INTEL_SIP_SMC_STATUS_REJECTED;
589 }
590
591 if (mode == SERVICE_COMPLETED_MODE_ASYNC) {
592 status = mailbox_read_response_async(job_id,
593 NULL, (uint32_t *) addr, &resp_len, 0);
594 } else {
595 status = mailbox_read_response(job_id,
596 (uint32_t *) addr, &resp_len);
597
598 if (status == MBOX_NO_RESPONSE) {
599 status = MBOX_BUSY;
600 }
601 }
602
603 if (status == MBOX_NO_RESPONSE) {
604 return INTEL_SIP_SMC_STATUS_NO_RESPONSE;
605 }
606
607 if (status == MBOX_BUSY) {
608 return INTEL_SIP_SMC_STATUS_BUSY;
609 }
610
611 *ret_size = resp_len * MBOX_WORD_BYTE;
612 flush_dcache_range(addr, *ret_size);
613
614 if (status != MBOX_RET_OK) {
615 *mbox_error = -status;
616 return INTEL_SIP_SMC_STATUS_ERROR;
617 }
618
619 return INTEL_SIP_SMC_STATUS_OK;
620}
621
Sieu Mun Tang758a2ad2022-05-11 10:23:13 +0800622/* Miscellaneous HPS services */
623uint32_t intel_hps_set_bridges(uint64_t enable, uint64_t mask)
624{
625 int status = 0;
626
Sieu Mun Tang044ed482022-05-11 10:45:19 +0800627 if ((enable & SOCFPGA_BRIDGE_ENABLE) != 0U) {
628 if ((enable & SOCFPGA_BRIDGE_HAS_MASK) != 0U) {
Sieu Mun Tang758a2ad2022-05-11 10:23:13 +0800629 status = socfpga_bridges_enable((uint32_t)mask);
630 } else {
631 status = socfpga_bridges_enable(~0);
632 }
633 } else {
Sieu Mun Tang044ed482022-05-11 10:45:19 +0800634 if ((enable & SOCFPGA_BRIDGE_HAS_MASK) != 0U) {
Sieu Mun Tang758a2ad2022-05-11 10:23:13 +0800635 status = socfpga_bridges_disable((uint32_t)mask);
636 } else {
637 status = socfpga_bridges_disable(~0);
638 }
639 }
640
641 if (status < 0) {
642 return INTEL_SIP_SMC_STATUS_ERROR;
643 }
644
645 return INTEL_SIP_SMC_STATUS_OK;
646}
647
Hadi Asyrafi616da772019-06-27 11:34:03 +0800648/*
649 * This function is responsible for handling all SiP calls from the NS world
650 */
651
Sieu Mun Tang044ed482022-05-11 10:45:19 +0800652uintptr_t sip_smc_handler_v1(uint32_t smc_fid,
Hadi Asyrafi616da772019-06-27 11:34:03 +0800653 u_register_t x1,
654 u_register_t x2,
655 u_register_t x3,
656 u_register_t x4,
657 void *cookie,
658 void *handle,
659 u_register_t flags)
660{
Sieu Mun Tang2a820b92022-05-11 09:59:55 +0800661 uint32_t retval = 0, completed_addr[3];
662 uint32_t retval2 = 0;
Sieu Mun Tanga34b8812022-03-17 03:11:55 +0800663 uint32_t mbox_error = 0;
Sieu Mun Tanga34b8812022-03-17 03:11:55 +0800664 uint64_t retval64, rsu_respbuf[9];
Sieu Mun Tang9f22cbf2022-03-02 11:04:09 +0800665 int status = INTEL_SIP_SMC_STATUS_OK;
Sieu Mun Tang24682662022-02-19 21:49:48 +0800666 int mbox_status;
667 unsigned int len_in_resp;
Sieu Mun Tang583149a2022-05-10 17:27:12 +0800668 u_register_t x5, x6, x7;
Abdul Halim, Muhammad Hadi Asyrafib45f15e2020-05-14 15:32:43 +0800669
Hadi Asyrafi616da772019-06-27 11:34:03 +0800670 switch (smc_fid) {
671 case SIP_SVC_UID:
672 /* Return UID to the caller */
673 SMC_UUID_RET(handle, intl_svc_uid);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800674
Hadi Asyrafi616da772019-06-27 11:34:03 +0800675 case INTEL_SIP_SMC_FPGA_CONFIG_ISDONE:
Sieu Mun Tangc3667602022-05-13 14:55:05 +0800676 status = intel_mailbox_fpga_config_isdone();
Hadi Asyrafi616da772019-06-27 11:34:03 +0800677 SMC_RET4(handle, status, 0, 0, 0);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800678
Hadi Asyrafi616da772019-06-27 11:34:03 +0800679 case INTEL_SIP_SMC_FPGA_CONFIG_GET_MEM:
680 SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK,
681 INTEL_SIP_SMC_FPGA_CONFIG_ADDR,
682 INTEL_SIP_SMC_FPGA_CONFIG_SIZE -
683 INTEL_SIP_SMC_FPGA_CONFIG_ADDR);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800684
Hadi Asyrafi616da772019-06-27 11:34:03 +0800685 case INTEL_SIP_SMC_FPGA_CONFIG_START:
686 status = intel_fpga_config_start(x1);
687 SMC_RET4(handle, status, 0, 0, 0);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800688
Hadi Asyrafi616da772019-06-27 11:34:03 +0800689 case INTEL_SIP_SMC_FPGA_CONFIG_WRITE:
690 status = intel_fpga_config_write(x1, x2);
691 SMC_RET4(handle, status, 0, 0, 0);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800692
Hadi Asyrafi616da772019-06-27 11:34:03 +0800693 case INTEL_SIP_SMC_FPGA_CONFIG_COMPLETED_WRITE:
694 status = intel_fpga_config_completed_write(completed_addr,
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800695 &retval, &rcv_id);
696 switch (retval) {
Hadi Asyrafi616da772019-06-27 11:34:03 +0800697 case 1:
698 SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK,
699 completed_addr[0], 0, 0);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800700
Hadi Asyrafi616da772019-06-27 11:34:03 +0800701 case 2:
702 SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK,
703 completed_addr[0],
704 completed_addr[1], 0);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800705
Hadi Asyrafi616da772019-06-27 11:34:03 +0800706 case 3:
707 SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK,
708 completed_addr[0],
709 completed_addr[1],
710 completed_addr[2]);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800711
Hadi Asyrafi616da772019-06-27 11:34:03 +0800712 case 0:
713 SMC_RET4(handle, status, 0, 0, 0);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800714
Hadi Asyrafi616da772019-06-27 11:34:03 +0800715 default:
Tien Hock, Loh500b2322019-10-30 14:49:40 +0800716 mailbox_clear_response();
Hadi Asyrafi616da772019-06-27 11:34:03 +0800717 SMC_RET1(handle, INTEL_SIP_SMC_STATUS_ERROR);
718 }
Hadi Asyrafi67942302019-10-22 13:28:51 +0800719
720 case INTEL_SIP_SMC_REG_READ:
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800721 status = intel_secure_reg_read(x1, &retval);
722 SMC_RET3(handle, status, retval, x1);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800723
724 case INTEL_SIP_SMC_REG_WRITE:
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800725 status = intel_secure_reg_write(x1, (uint32_t)x2, &retval);
726 SMC_RET3(handle, status, retval, x1);
Hadi Asyrafi67942302019-10-22 13:28:51 +0800727
728 case INTEL_SIP_SMC_REG_UPDATE:
729 status = intel_secure_reg_update(x1, (uint32_t)x2,
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800730 (uint32_t)x3, &retval);
731 SMC_RET3(handle, status, retval, x1);
Hadi Asyrafi616da772019-06-27 11:34:03 +0800732
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800733 case INTEL_SIP_SMC_RSU_STATUS:
734 status = intel_rsu_status(rsu_respbuf,
735 ARRAY_SIZE(rsu_respbuf));
736 if (status) {
737 SMC_RET1(handle, status);
738 } else {
739 SMC_RET4(handle, rsu_respbuf[0], rsu_respbuf[1],
740 rsu_respbuf[2], rsu_respbuf[3]);
741 }
742
743 case INTEL_SIP_SMC_RSU_UPDATE:
744 status = intel_rsu_update(x1);
745 SMC_RET1(handle, status);
746
747 case INTEL_SIP_SMC_RSU_NOTIFY:
748 status = intel_rsu_notify(x1);
749 SMC_RET1(handle, status);
750
751 case INTEL_SIP_SMC_RSU_RETRY_COUNTER:
752 status = intel_rsu_retry_counter((uint32_t *)rsu_respbuf,
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800753 ARRAY_SIZE(rsu_respbuf), &retval);
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800754 if (status) {
755 SMC_RET1(handle, status);
756 } else {
Abdul Halim, Muhammad Hadi Asyrafi20a07f32020-05-18 11:16:48 +0800757 SMC_RET2(handle, status, retval);
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800758 }
759
Chee Hong Ang2cfd8ec2020-05-13 11:44:04 +0800760 case INTEL_SIP_SMC_RSU_DCMF_VERSION:
761 SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK,
762 ((uint64_t)rsu_dcmf_ver[1] << 32) | rsu_dcmf_ver[0],
763 ((uint64_t)rsu_dcmf_ver[3] << 32) | rsu_dcmf_ver[2]);
764
765 case INTEL_SIP_SMC_RSU_COPY_DCMF_VERSION:
766 status = intel_rsu_copy_dcmf_version(x1, x2);
767 SMC_RET1(handle, status);
768
Sieu Mun Tange6d5de92022-04-28 22:21:01 +0800769 case INTEL_SIP_SMC_RSU_DCMF_STATUS:
770 SMC_RET2(handle, INTEL_SIP_SMC_STATUS_OK,
771 ((uint64_t)rsu_dcmf_stat[3] << 48) |
772 ((uint64_t)rsu_dcmf_stat[2] << 32) |
773 ((uint64_t)rsu_dcmf_stat[1] << 16) |
774 rsu_dcmf_stat[0]);
775
776 case INTEL_SIP_SMC_RSU_COPY_DCMF_STATUS:
777 status = intel_rsu_copy_dcmf_status(x1);
778 SMC_RET1(handle, status);
779
Chee Hong Ang681631b2020-07-01 14:22:25 +0800780 case INTEL_SIP_SMC_RSU_MAX_RETRY:
781 SMC_RET2(handle, INTEL_SIP_SMC_STATUS_OK, rsu_max_retry);
782
783 case INTEL_SIP_SMC_RSU_COPY_MAX_RETRY:
784 rsu_max_retry = x1;
785 SMC_RET1(handle, INTEL_SIP_SMC_STATUS_OK);
786
Sieu Mun Tangdbcc2cf2022-03-07 12:13:04 +0800787 case INTEL_SIP_SMC_ECC_DBE:
788 status = intel_ecc_dbe_notification(x1);
789 SMC_RET1(handle, status);
790
Sieu Mun Tang758a2ad2022-05-11 10:23:13 +0800791 case INTEL_SIP_SMC_SERVICE_COMPLETED:
792 status = intel_smc_service_completed(x1, x2, x3, &rcv_id,
793 &len_in_resp, &mbox_error);
794 SMC_RET4(handle, status, mbox_error, x1, len_in_resp);
795
Abdul Halim, Muhammad Hadi Asyrafid9006fc2021-02-05 11:50:58 +0800796 case INTEL_SIP_SMC_FIRMWARE_VERSION:
797 status = intel_smc_fw_version(&retval);
Sieu Mun Tangbfda95a2022-04-27 18:54:10 +0800798 SMC_RET2(handle, status, retval);
Abdul Halim, Muhammad Hadi Asyrafid9006fc2021-02-05 11:50:58 +0800799
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800800 case INTEL_SIP_SMC_MBOX_SEND_CMD:
801 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
802 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
Sieu Mun Tang7420c532022-05-10 23:17:04 +0800803 status = intel_mbox_send_cmd(x1, (uint32_t *)x2, x3, x4, x5, x6,
804 &mbox_status, &len_in_resp);
Sieu Mun Tangf02f0cb2022-02-19 20:36:41 +0800805 SMC_RET3(handle, status, mbox_status, len_in_resp);
Hadi Asyrafia33e8102019-12-17 19:30:41 +0800806
Sieu Mun Tang2b8e0052022-04-27 18:57:29 +0800807 case INTEL_SIP_SMC_GET_USERCODE:
808 status = intel_smc_get_usercode(&retval);
809 SMC_RET2(handle, status, retval);
810
Sieu Mun Tang128d2a72022-05-11 09:49:25 +0800811 case INTEL_SIP_SMC_FCS_CRYPTION:
812 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
813
814 if (x1 == FCS_MODE_DECRYPT) {
815 status = intel_fcs_decryption(x2, x3, x4, x5, &send_id);
816 } else if (x1 == FCS_MODE_ENCRYPT) {
817 status = intel_fcs_encryption(x2, x3, x4, x5, &send_id);
818 } else {
819 status = INTEL_SIP_SMC_STATUS_REJECTED;
820 }
821
822 SMC_RET3(handle, status, x4, x5);
823
Sieu Mun Tang22322fb2022-05-09 16:05:58 +0800824 case INTEL_SIP_SMC_FCS_CRYPTION_EXT:
825 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
826 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
827 x7 = SMC_GET_GP(handle, CTX_GPREG_X7);
828
829 if (x3 == FCS_MODE_DECRYPT) {
830 status = intel_fcs_decryption_ext(x1, x2, x4, x5, x6,
831 (uint32_t *) &x7, &mbox_error);
832 } else if (x3 == FCS_MODE_ENCRYPT) {
833 status = intel_fcs_encryption_ext(x1, x2, x4, x5, x6,
834 (uint32_t *) &x7, &mbox_error);
835 } else {
836 status = INTEL_SIP_SMC_STATUS_REJECTED;
837 }
838
839 SMC_RET4(handle, status, mbox_error, x6, x7);
840
Sieu Mun Tangfd8a8ad2022-05-07 00:50:37 +0800841 case INTEL_SIP_SMC_FCS_RANDOM_NUMBER:
842 status = intel_fcs_random_number_gen(x1, &retval64,
843 &mbox_error);
844 SMC_RET4(handle, status, mbox_error, x1, retval64);
845
Sieu Mun Tange7a037f2022-05-10 17:18:19 +0800846 case INTEL_SIP_SMC_FCS_RANDOM_NUMBER_EXT:
847 status = intel_fcs_random_number_gen_ext(x1, x2, x3,
848 &send_id);
849 SMC_RET1(handle, status);
850
Sieu Mun Tangfd8a8ad2022-05-07 00:50:37 +0800851 case INTEL_SIP_SMC_FCS_SEND_CERTIFICATE:
852 status = intel_fcs_send_cert(x1, x2, &send_id);
853 SMC_RET1(handle, status);
854
855 case INTEL_SIP_SMC_FCS_GET_PROVISION_DATA:
856 status = intel_fcs_get_provision_data(&send_id);
857 SMC_RET1(handle, status);
858
Sieu Mun Tanga068fdf2022-05-11 10:01:54 +0800859 case INTEL_SIP_SMC_FCS_CNTR_SET_PREAUTH:
860 status = intel_fcs_cntr_set_preauth(x1, x2, x3,
861 &mbox_error);
862 SMC_RET2(handle, status, mbox_error);
863
Sieu Mun Tang82cf5df2022-05-05 17:07:21 +0800864 case INTEL_SIP_SMC_HPS_SET_BRIDGES:
865 status = intel_hps_set_bridges(x1, x2);
866 SMC_RET1(handle, status);
867
Sieu Mun Tang044ed482022-05-11 10:45:19 +0800868 case INTEL_SIP_SMC_HWMON_READTEMP:
869 status = intel_hwmon_readtemp(x1, &retval);
870 SMC_RET2(handle, status, retval);
871
872 case INTEL_SIP_SMC_HWMON_READVOLT:
873 status = intel_hwmon_readvolt(x1, &retval);
874 SMC_RET2(handle, status, retval);
875
Sieu Mun Tang2a820b92022-05-11 09:59:55 +0800876 case INTEL_SIP_SMC_FCS_PSGSIGMA_TEARDOWN:
877 status = intel_fcs_sigma_teardown(x1, &mbox_error);
878 SMC_RET2(handle, status, mbox_error);
879
880 case INTEL_SIP_SMC_FCS_CHIP_ID:
881 status = intel_fcs_chip_id(&retval, &retval2, &mbox_error);
882 SMC_RET4(handle, status, mbox_error, retval, retval2);
883
884 case INTEL_SIP_SMC_FCS_ATTESTATION_SUBKEY:
885 status = intel_fcs_attestation_subkey(x1, x2, x3,
886 (uint32_t *) &x4, &mbox_error);
887 SMC_RET4(handle, status, mbox_error, x3, x4);
888
889 case INTEL_SIP_SMC_FCS_ATTESTATION_MEASUREMENTS:
890 status = intel_fcs_get_measurement(x1, x2, x3,
891 (uint32_t *) &x4, &mbox_error);
892 SMC_RET4(handle, status, mbox_error, x3, x4);
893
Sieu Mun Tang28af1652022-05-09 10:48:53 +0800894 case INTEL_SIP_SMC_FCS_GET_ATTESTATION_CERT:
895 status = intel_fcs_get_attestation_cert(x1, x2,
896 (uint32_t *) &x3, &mbox_error);
897 SMC_RET4(handle, status, mbox_error, x2, x3);
898
899 case INTEL_SIP_SMC_FCS_CREATE_CERT_ON_RELOAD:
900 status = intel_fcs_create_cert_on_reload(x1, &mbox_error);
901 SMC_RET2(handle, status, mbox_error);
902
Sieu Mun Tang16754e12022-05-09 12:08:42 +0800903 case INTEL_SIP_SMC_FCS_OPEN_CS_SESSION:
904 status = intel_fcs_open_crypto_service_session(&retval, &mbox_error);
905 SMC_RET3(handle, status, mbox_error, retval);
906
907 case INTEL_SIP_SMC_FCS_CLOSE_CS_SESSION:
908 status = intel_fcs_close_crypto_service_session(x1, &mbox_error);
909 SMC_RET2(handle, status, mbox_error);
910
Sieu Mun Tangfb1f6e92022-05-09 14:16:14 +0800911 case INTEL_SIP_SMC_FCS_IMPORT_CS_KEY:
912 status = intel_fcs_import_crypto_service_key(x1, x2, &send_id);
913 SMC_RET1(handle, status);
914
915 case INTEL_SIP_SMC_FCS_EXPORT_CS_KEY:
916 status = intel_fcs_export_crypto_service_key(x1, x2, x3,
917 (uint32_t *) &x4, &mbox_error);
918 SMC_RET4(handle, status, mbox_error, x3, x4);
919
920 case INTEL_SIP_SMC_FCS_REMOVE_CS_KEY:
921 status = intel_fcs_remove_crypto_service_key(x1, x2,
922 &mbox_error);
923 SMC_RET2(handle, status, mbox_error);
924
925 case INTEL_SIP_SMC_FCS_GET_CS_KEY_INFO:
926 status = intel_fcs_get_crypto_service_key_info(x1, x2, x3,
927 (uint32_t *) &x4, &mbox_error);
928 SMC_RET4(handle, status, mbox_error, x3, x4);
929
Sieu Mun Tangd907cc32022-05-10 17:24:05 +0800930 case INTEL_SIP_SMC_FCS_GET_DIGEST_INIT:
931 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
932 status = intel_fcs_get_digest_init(x1, x2, x3,
933 x4, x5, &mbox_error);
934 SMC_RET2(handle, status, mbox_error);
935
Sieu Mun Tang527df9f2022-04-28 16:28:48 +0800936 case INTEL_SIP_SMC_FCS_GET_DIGEST_UPDATE:
937 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
938 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
939 status = intel_fcs_get_digest_update_finalize(x1, x2, x3,
940 x4, x5, (uint32_t *) &x6, false,
941 &mbox_error);
942 SMC_RET4(handle, status, mbox_error, x5, x6);
943
Sieu Mun Tangd907cc32022-05-10 17:24:05 +0800944 case INTEL_SIP_SMC_FCS_GET_DIGEST_FINALIZE:
945 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
946 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
Sieu Mun Tang527df9f2022-04-28 16:28:48 +0800947 status = intel_fcs_get_digest_update_finalize(x1, x2, x3,
948 x4, x5, (uint32_t *) &x6, true,
949 &mbox_error);
Sieu Mun Tangd907cc32022-05-10 17:24:05 +0800950 SMC_RET4(handle, status, mbox_error, x5, x6);
951
Sieu Mun Tangbd8da632022-09-28 15:58:28 +0800952 case INTEL_SIP_SMC_FCS_GET_DIGEST_SMMU_UPDATE:
953 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
954 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
955 status = intel_fcs_get_digest_smmu_update_finalize(x1, x2, x3,
956 x4, x5, (uint32_t *) &x6, false,
957 &mbox_error, &send_id);
958 SMC_RET4(handle, status, mbox_error, x5, x6);
959
960 case INTEL_SIP_SMC_FCS_GET_DIGEST_SMMU_FINALIZE:
961 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
962 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
963 status = intel_fcs_get_digest_smmu_update_finalize(x1, x2, x3,
964 x4, x5, (uint32_t *) &x6, true,
965 &mbox_error, &send_id);
966 SMC_RET4(handle, status, mbox_error, x5, x6);
967
Sieu Mun Tang583149a2022-05-10 17:27:12 +0800968 case INTEL_SIP_SMC_FCS_MAC_VERIFY_INIT:
969 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
970 status = intel_fcs_mac_verify_init(x1, x2, x3,
971 x4, x5, &mbox_error);
972 SMC_RET2(handle, status, mbox_error);
973
Sieu Mun Tang527df9f2022-04-28 16:28:48 +0800974 case INTEL_SIP_SMC_FCS_MAC_VERIFY_UPDATE:
975 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
976 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
977 x7 = SMC_GET_GP(handle, CTX_GPREG_X7);
978 status = intel_fcs_mac_verify_update_finalize(x1, x2, x3,
979 x4, x5, (uint32_t *) &x6, x7,
980 false, &mbox_error);
981 SMC_RET4(handle, status, mbox_error, x5, x6);
982
Sieu Mun Tang583149a2022-05-10 17:27:12 +0800983 case INTEL_SIP_SMC_FCS_MAC_VERIFY_FINALIZE:
984 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
985 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
986 x7 = SMC_GET_GP(handle, CTX_GPREG_X7);
Sieu Mun Tang527df9f2022-04-28 16:28:48 +0800987 status = intel_fcs_mac_verify_update_finalize(x1, x2, x3,
988 x4, x5, (uint32_t *) &x6, x7,
989 true, &mbox_error);
Sieu Mun Tang583149a2022-05-10 17:27:12 +0800990 SMC_RET4(handle, status, mbox_error, x5, x6);
991
Sieu Mun Tangbd8da632022-09-28 15:58:28 +0800992 case INTEL_SIP_SMC_FCS_MAC_VERIFY_SMMU_UPDATE:
993 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
994 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
995 x7 = SMC_GET_GP(handle, CTX_GPREG_X7);
996 status = intel_fcs_mac_verify_smmu_update_finalize(x1, x2, x3,
997 x4, x5, (uint32_t *) &x6, x7,
998 false, &mbox_error, &send_id);
999 SMC_RET4(handle, status, mbox_error, x5, x6);
1000
1001 case INTEL_SIP_SMC_FCS_MAC_VERIFY_SMMU_FINALIZE:
1002 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1003 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
1004 x7 = SMC_GET_GP(handle, CTX_GPREG_X7);
1005 status = intel_fcs_mac_verify_smmu_update_finalize(x1, x2, x3,
1006 x4, x5, (uint32_t *) &x6, x7,
1007 true, &mbox_error, &send_id);
1008 SMC_RET4(handle, status, mbox_error, x5, x6);
1009
Sieu Mun Tang153ecfb2022-05-10 17:39:26 +08001010 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIGN_INIT:
1011 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1012 status = intel_fcs_ecdsa_sha2_data_sign_init(x1, x2, x3,
1013 x4, x5, &mbox_error);
1014 SMC_RET2(handle, status, mbox_error);
1015
Sieu Mun Tange77d37d2022-04-28 16:23:20 +08001016 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIGN_UPDATE:
1017 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1018 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
1019 status = intel_fcs_ecdsa_sha2_data_sign_update_finalize(x1, x2,
1020 x3, x4, x5, (uint32_t *) &x6, false,
1021 &mbox_error);
1022 SMC_RET4(handle, status, mbox_error, x5, x6);
1023
Sieu Mun Tang153ecfb2022-05-10 17:39:26 +08001024 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIGN_FINALIZE:
1025 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1026 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
Sieu Mun Tange77d37d2022-04-28 16:23:20 +08001027 status = intel_fcs_ecdsa_sha2_data_sign_update_finalize(x1, x2,
1028 x3, x4, x5, (uint32_t *) &x6, true,
1029 &mbox_error);
Sieu Mun Tang153ecfb2022-05-10 17:39:26 +08001030 SMC_RET4(handle, status, mbox_error, x5, x6);
1031
Sieu Mun Tangbd8da632022-09-28 15:58:28 +08001032 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIGN_SMMU_UPDATE:
1033 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1034 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
1035 status = intel_fcs_ecdsa_sha2_data_sign_smmu_update_finalize(x1,
1036 x2, x3, x4, x5, (uint32_t *) &x6, false,
1037 &mbox_error, &send_id);
1038 SMC_RET4(handle, status, mbox_error, x5, x6);
1039
1040 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIGN_SMMU_FINALIZE:
1041 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1042 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
1043 status = intel_fcs_ecdsa_sha2_data_sign_smmu_update_finalize(x1,
1044 x2, x3, x4, x5, (uint32_t *) &x6, true,
1045 &mbox_error, &send_id);
1046 SMC_RET4(handle, status, mbox_error, x5, x6);
1047
Sieu Mun Tang8aa05ad2022-05-10 17:50:30 +08001048 case INTEL_SIP_SMC_FCS_ECDSA_HASH_SIGN_INIT:
1049 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1050 status = intel_fcs_ecdsa_hash_sign_init(x1, x2, x3,
1051 x4, x5, &mbox_error);
1052 SMC_RET2(handle, status, mbox_error);
1053
1054 case INTEL_SIP_SMC_FCS_ECDSA_HASH_SIGN_FINALIZE:
1055 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1056 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
1057 status = intel_fcs_ecdsa_hash_sign_finalize(x1, x2, x3,
1058 x4, x5, (uint32_t *) &x6, &mbox_error);
1059 SMC_RET4(handle, status, mbox_error, x5, x6);
1060
Sieu Mun Tang59357e82022-05-10 17:53:32 +08001061 case INTEL_SIP_SMC_FCS_ECDSA_HASH_SIG_VERIFY_INIT:
1062 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1063 status = intel_fcs_ecdsa_hash_sig_verify_init(x1, x2, x3,
1064 x4, x5, &mbox_error);
1065 SMC_RET2(handle, status, mbox_error);
1066
1067 case INTEL_SIP_SMC_FCS_ECDSA_HASH_SIG_VERIFY_FINALIZE:
1068 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1069 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
1070 status = intel_fcs_ecdsa_hash_sig_verify_finalize(x1, x2, x3,
1071 x4, x5, (uint32_t *) &x6, &mbox_error);
1072 SMC_RET4(handle, status, mbox_error, x5, x6);
1073
Sieu Mun Tangdcaab772022-05-11 10:16:40 +08001074 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIG_VERIFY_INIT:
1075 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1076 status = intel_fcs_ecdsa_sha2_data_sig_verify_init(x1, x2, x3,
1077 x4, x5, &mbox_error);
1078 SMC_RET2(handle, status, mbox_error);
1079
Sieu Mun Tange77d37d2022-04-28 16:23:20 +08001080 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIG_VERIFY_UPDATE:
1081 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1082 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
1083 x7 = SMC_GET_GP(handle, CTX_GPREG_X7);
1084 status = intel_fcs_ecdsa_sha2_data_sig_verify_update_finalize(
1085 x1, x2, x3, x4, x5, (uint32_t *) &x6,
1086 x7, false, &mbox_error);
1087 SMC_RET4(handle, status, mbox_error, x5, x6);
1088
Sieu Mun Tangbd8da632022-09-28 15:58:28 +08001089 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIG_VERIFY_SMMU_UPDATE:
1090 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1091 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
1092 x7 = SMC_GET_GP(handle, CTX_GPREG_X7);
1093 status = intel_fcs_ecdsa_sha2_data_sig_verify_smmu_update_finalize(
1094 x1, x2, x3, x4, x5, (uint32_t *) &x6,
1095 x7, false, &mbox_error, &send_id);
1096 SMC_RET4(handle, status, mbox_error, x5, x6);
1097
1098 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIG_VERIFY_SMMU_FINALIZE:
1099 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1100 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
1101 x7 = SMC_GET_GP(handle, CTX_GPREG_X7);
1102 status = intel_fcs_ecdsa_sha2_data_sig_verify_smmu_update_finalize(
1103 x1, x2, x3, x4, x5, (uint32_t *) &x6,
1104 x7, true, &mbox_error, &send_id);
1105 SMC_RET4(handle, status, mbox_error, x5, x6);
1106
Sieu Mun Tangdcaab772022-05-11 10:16:40 +08001107 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIG_VERIFY_FINALIZE:
1108 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1109 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
1110 x7 = SMC_GET_GP(handle, CTX_GPREG_X7);
Sieu Mun Tange77d37d2022-04-28 16:23:20 +08001111 status = intel_fcs_ecdsa_sha2_data_sig_verify_update_finalize(
1112 x1, x2, x3, x4, x5, (uint32_t *) &x6,
1113 x7, true, &mbox_error);
Sieu Mun Tangdcaab772022-05-11 10:16:40 +08001114 SMC_RET4(handle, status, mbox_error, x5, x6);
Sieu Mun Tang153ecfb2022-05-10 17:39:26 +08001115
Sieu Mun Tange2f3ede2022-05-10 17:36:32 +08001116 case INTEL_SIP_SMC_FCS_ECDSA_GET_PUBKEY_INIT:
1117 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1118 status = intel_fcs_ecdsa_get_pubkey_init(x1, x2, x3,
1119 x4, x5, &mbox_error);
1120 SMC_RET2(handle, status, mbox_error);
1121
1122 case INTEL_SIP_SMC_FCS_ECDSA_GET_PUBKEY_FINALIZE:
1123 status = intel_fcs_ecdsa_get_pubkey_finalize(x1, x2, x3,
1124 (uint32_t *) &x4, &mbox_error);
1125 SMC_RET4(handle, status, mbox_error, x3, x4);
1126
Sieu Mun Tang0675c222022-05-10 17:48:11 +08001127 case INTEL_SIP_SMC_FCS_ECDH_REQUEST_INIT:
1128 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1129 status = intel_fcs_ecdh_request_init(x1, x2, x3,
1130 x4, x5, &mbox_error);
1131 SMC_RET2(handle, status, mbox_error);
1132
1133 case INTEL_SIP_SMC_FCS_ECDH_REQUEST_FINALIZE:
1134 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1135 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
1136 status = intel_fcs_ecdh_request_finalize(x1, x2, x3,
1137 x4, x5, (uint32_t *) &x6, &mbox_error);
1138 SMC_RET4(handle, status, mbox_error, x5, x6);
1139
Sieu Mun Tangb0c1d112022-05-10 17:30:00 +08001140 case INTEL_SIP_SMC_FCS_AES_CRYPT_INIT:
1141 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1142 status = intel_fcs_aes_crypt_init(x1, x2, x3, x4, x5,
1143 &mbox_error);
1144 SMC_RET2(handle, status, mbox_error);
1145
Sieu Mun Tang9bea8152022-04-28 16:15:54 +08001146 case INTEL_SIP_SMC_FCS_AES_CRYPT_UPDATE:
1147 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1148 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
1149 status = intel_fcs_aes_crypt_update_finalize(x1, x2, x3, x4,
1150 x5, x6, false, &send_id);
1151 SMC_RET1(handle, status);
1152
Sieu Mun Tangb0c1d112022-05-10 17:30:00 +08001153 case INTEL_SIP_SMC_FCS_AES_CRYPT_FINALIZE:
1154 x5 = SMC_GET_GP(handle, CTX_GPREG_X5);
1155 x6 = SMC_GET_GP(handle, CTX_GPREG_X6);
Sieu Mun Tang9bea8152022-04-28 16:15:54 +08001156 status = intel_fcs_aes_crypt_update_finalize(x1, x2, x3, x4,
1157 x5, x6, true, &send_id);
Sieu Mun Tangb0c1d112022-05-10 17:30:00 +08001158 SMC_RET1(handle, status);
1159
Sieu Mun Tanga34b8812022-03-17 03:11:55 +08001160 case INTEL_SIP_SMC_GET_ROM_PATCH_SHA384:
1161 status = intel_fcs_get_rom_patch_sha384(x1, &retval64,
1162 &mbox_error);
1163 SMC_RET4(handle, status, mbox_error, x1, retval64);
1164
Sieu Mun Tangf9cb6572022-04-27 18:24:06 +08001165 case INTEL_SIP_SMC_SVC_VERSION:
1166 SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK,
1167 SIP_SVC_VERSION_MAJOR,
1168 SIP_SVC_VERSION_MINOR);
1169
Hadi Asyrafi616da772019-06-27 11:34:03 +08001170 default:
1171 return socfpga_sip_handler(smc_fid, x1, x2, x3, x4,
1172 cookie, handle, flags);
1173 }
1174}
1175
Sieu Mun Tang044ed482022-05-11 10:45:19 +08001176uintptr_t sip_smc_handler(uint32_t smc_fid,
1177 u_register_t x1,
1178 u_register_t x2,
1179 u_register_t x3,
1180 u_register_t x4,
1181 void *cookie,
1182 void *handle,
1183 u_register_t flags)
1184{
1185 uint32_t cmd = smc_fid & INTEL_SIP_SMC_CMD_MASK;
1186
1187 if (cmd >= INTEL_SIP_SMC_CMD_V2_RANGE_BEGIN &&
1188 cmd <= INTEL_SIP_SMC_CMD_V2_RANGE_END) {
1189 return sip_smc_handler_v2(smc_fid, x1, x2, x3, x4,
1190 cookie, handle, flags);
1191 } else {
1192 return sip_smc_handler_v1(smc_fid, x1, x2, x3, x4,
1193 cookie, handle, flags);
1194 }
1195}
1196
Hadi Asyrafi616da772019-06-27 11:34:03 +08001197DECLARE_RT_SVC(
Hadi Asyrafi4d9f3952019-10-23 17:35:32 +08001198 socfpga_sip_svc,
Hadi Asyrafi616da772019-06-27 11:34:03 +08001199 OEN_SIP_START,
1200 OEN_SIP_END,
1201 SMC_TYPE_FAST,
1202 NULL,
1203 sip_smc_handler
1204);
1205
1206DECLARE_RT_SVC(
Hadi Asyrafi4d9f3952019-10-23 17:35:32 +08001207 socfpga_sip_svc_std,
Hadi Asyrafi616da772019-06-27 11:34:03 +08001208 OEN_SIP_START,
1209 OEN_SIP_END,
1210 SMC_TYPE_YIELD,
1211 NULL,
1212 sip_smc_handler
1213);