1 /* 2 * Copyright (c) 2019-2023, ARM Limited and Contributors. All rights reserved. 3 * Copyright (c) 2019-2023, Intel Corporation. All rights reserved. 4 * Copyright (c) 2024-2025, Altera Corporation. All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #include <assert.h> 10 #include <common/debug.h> 11 #include <common/runtime_svc.h> 12 #include <lib/mmio.h> 13 #include <tools_share/uuid.h> 14 15 #include "socfpga_fcs.h" 16 #include "socfpga_mailbox.h" 17 #include "socfpga_plat_def.h" 18 #include "socfpga_reset_manager.h" 19 #include "socfpga_sip_svc.h" 20 #include "socfpga_system_manager.h" 21 22 /* Total buffer the driver can hold */ 23 #define FPGA_CONFIG_BUFFER_SIZE 4 24 25 static config_type request_type = NO_REQUEST; 26 static int current_block, current_buffer; 27 static int read_block, max_blocks; 28 static uint32_t send_id, rcv_id; 29 static uint32_t bytes_per_block, blocks_submitted; 30 static bool bridge_disable; 31 #if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5 32 static uint32_t g_remapper_bypass; 33 #endif 34 35 /* RSU static variables */ 36 static uint32_t rsu_dcmf_ver[4] = {0}; 37 static uint16_t rsu_dcmf_stat[4] = {0}; 38 static uint32_t rsu_max_retry; 39 40 /* SiP Service UUID */ 41 DEFINE_SVC_UUID2(intl_svc_uid, 42 0xa85273b0, 0xe85a, 0x4862, 0xa6, 0x2a, 43 0xfa, 0x88, 0x88, 0x17, 0x68, 0x81); 44 45 static uint64_t socfpga_sip_handler(uint32_t smc_fid, 46 uint64_t x1, 47 uint64_t x2, 48 uint64_t x3, 49 uint64_t x4, 50 void *cookie, 51 void *handle, 52 uint64_t flags) 53 { 54 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); 55 SMC_RET1(handle, SMC_UNK); 56 } 57 58 struct fpga_config_info fpga_config_buffers[FPGA_CONFIG_BUFFER_SIZE]; 59 60 static int intel_fpga_sdm_write_buffer(struct fpga_config_info *buffer) 61 { 62 uint32_t args[3]; 63 64 while (max_blocks > 0 && buffer->size > buffer->size_written) { 65 args[0] = (1<<8); 66 args[1] = buffer->addr + buffer->size_written; 67 if (buffer->size - buffer->size_written <= bytes_per_block) { 68 args[2] = buffer->size - buffer->size_written; 69 current_buffer++; 70 current_buffer %= FPGA_CONFIG_BUFFER_SIZE; 71 } else { 72 args[2] = bytes_per_block; 73 } 74 75 buffer->size_written += args[2]; 76 mailbox_send_cmd_async(&send_id, MBOX_RECONFIG_DATA, args, 77 3U, CMD_INDIRECT); 78 79 buffer->subblocks_sent++; 80 max_blocks--; 81 } 82 83 return !max_blocks; 84 } 85 86 static int intel_fpga_sdm_write_all(void) 87 { 88 for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) { 89 if (intel_fpga_sdm_write_buffer( 90 &fpga_config_buffers[current_buffer])) { 91 break; 92 } 93 } 94 return 0; 95 } 96 97 static uint32_t intel_mailbox_fpga_config_isdone(uint32_t *err_states) 98 { 99 uint32_t ret; 100 101 if (err_states == NULL) 102 return INTEL_SIP_SMC_STATUS_REJECTED; 103 104 switch (request_type) { 105 case RECONFIGURATION: 106 ret = intel_mailbox_get_config_status(MBOX_RECONFIG_STATUS, 107 true, err_states); 108 break; 109 case BITSTREAM_AUTH: 110 ret = intel_mailbox_get_config_status(MBOX_RECONFIG_STATUS, 111 false, err_states); 112 break; 113 default: 114 ret = intel_mailbox_get_config_status(MBOX_CONFIG_STATUS, 115 false, err_states); 116 break; 117 } 118 119 if (ret != 0U) { 120 if (ret == MBOX_CFGSTAT_STATE_CONFIG) { 121 return INTEL_SIP_SMC_STATUS_BUSY; 122 } else { 123 request_type = NO_REQUEST; 124 return INTEL_SIP_SMC_STATUS_ERROR; 125 } 126 } 127 128 if (bridge_disable != 0U) { 129 socfpga_bridges_enable(~0); /* Enable bridge */ 130 bridge_disable = false; 131 } 132 request_type = NO_REQUEST; 133 134 return INTEL_SIP_SMC_STATUS_OK; 135 } 136 137 static int mark_last_buffer_xfer_completed(uint32_t *buffer_addr_completed) 138 { 139 int i; 140 141 for (i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) { 142 if (fpga_config_buffers[i].block_number == current_block) { 143 fpga_config_buffers[i].subblocks_sent--; 144 if (fpga_config_buffers[i].subblocks_sent == 0 145 && fpga_config_buffers[i].size <= 146 fpga_config_buffers[i].size_written) { 147 fpga_config_buffers[i].write_requested = 0; 148 current_block++; 149 *buffer_addr_completed = 150 fpga_config_buffers[i].addr; 151 return 0; 152 } 153 } 154 } 155 156 return -1; 157 } 158 159 static int intel_fpga_config_completed_write(uint32_t *completed_addr, 160 uint32_t *count, uint32_t *job_id) 161 { 162 uint32_t resp[5]; 163 unsigned int resp_len = ARRAY_SIZE(resp); 164 int status = INTEL_SIP_SMC_STATUS_OK; 165 int all_completed = 1; 166 *count = 0; 167 168 while (*count < 3) { 169 170 status = mailbox_read_response(job_id, 171 resp, &resp_len); 172 173 if (status < 0) { 174 break; 175 } 176 177 max_blocks++; 178 179 if (mark_last_buffer_xfer_completed( 180 &completed_addr[*count]) == 0) { 181 *count = *count + 1; 182 } else { 183 break; 184 } 185 } 186 187 if (*count <= 0) { 188 if (status != MBOX_NO_RESPONSE && 189 status != MBOX_TIMEOUT && resp_len != 0) { 190 mailbox_clear_response(); 191 request_type = NO_REQUEST; 192 return INTEL_SIP_SMC_STATUS_ERROR; 193 } 194 195 *count = 0; 196 } 197 198 intel_fpga_sdm_write_all(); 199 200 if (*count > 0) { 201 status = INTEL_SIP_SMC_STATUS_OK; 202 } else if (*count == 0) { 203 status = INTEL_SIP_SMC_STATUS_BUSY; 204 } 205 206 for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) { 207 if (fpga_config_buffers[i].write_requested != 0) { 208 all_completed = 0; 209 break; 210 } 211 } 212 213 if (all_completed == 1) { 214 return INTEL_SIP_SMC_STATUS_OK; 215 } 216 217 return status; 218 } 219 220 static int intel_fpga_config_start(uint32_t flag) 221 { 222 uint32_t argument = 0x1; 223 uint32_t response[3]; 224 int status = 0; 225 unsigned int size = 0; 226 unsigned int resp_len = ARRAY_SIZE(response); 227 228 #if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5 229 /* 230 * To trigger isolation 231 * FPGA configuration complete signal should be de-asserted 232 */ 233 INFO("SOCFPGA: Request SDM to trigger isolation\n"); 234 status = mailbox_send_fpga_config_comp(); 235 236 if (status < 0) { 237 INFO("SOCFPGA: Isolation for FPGA configuration complete is not executed\n"); 238 } 239 #endif 240 241 request_type = RECONFIGURATION; 242 243 if (!CONFIG_TEST_FLAG(flag, PARTIAL_CONFIG)) { 244 bridge_disable = true; 245 } 246 247 if (CONFIG_TEST_FLAG(flag, AUTHENTICATION)) { 248 size = 1; 249 bridge_disable = false; 250 request_type = BITSTREAM_AUTH; 251 } 252 253 #if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5 254 intel_smmu_hps_remapper_init(0U); 255 #endif 256 257 mailbox_clear_response(); 258 259 mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_CANCEL, NULL, 0U, 260 CMD_CASUAL, NULL, NULL); 261 262 status = mailbox_send_cmd(MBOX_JOB_ID, MBOX_RECONFIG, &argument, size, 263 CMD_CASUAL, response, &resp_len); 264 265 if (status < 0) { 266 bridge_disable = false; 267 request_type = NO_REQUEST; 268 return INTEL_SIP_SMC_STATUS_ERROR; 269 } 270 271 max_blocks = response[0]; 272 bytes_per_block = response[1]; 273 274 for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) { 275 fpga_config_buffers[i].size = 0; 276 fpga_config_buffers[i].size_written = 0; 277 fpga_config_buffers[i].addr = 0; 278 fpga_config_buffers[i].write_requested = 0; 279 fpga_config_buffers[i].block_number = 0; 280 fpga_config_buffers[i].subblocks_sent = 0; 281 } 282 283 blocks_submitted = 0; 284 current_block = 0; 285 read_block = 0; 286 current_buffer = 0; 287 288 /* Disable bridge on full reconfiguration */ 289 if (bridge_disable) { 290 socfpga_bridges_disable(~0); 291 } 292 293 return INTEL_SIP_SMC_STATUS_OK; 294 } 295 296 static bool is_fpga_config_buffer_full(void) 297 { 298 for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) { 299 if (!fpga_config_buffers[i].write_requested) { 300 return false; 301 } 302 } 303 return true; 304 } 305 306 bool is_address_in_ddr_range(uint64_t addr, uint64_t size) 307 { 308 uint128_t dram_max_sz = (uint128_t)DRAM_BASE + (uint128_t)DRAM_SIZE; 309 uint128_t dram_region_end = (uint128_t)addr + (uint128_t)size; 310 311 if (!addr && !size) { 312 return true; 313 } 314 if (size > (UINT64_MAX - addr)) { 315 return false; 316 } 317 if (addr < BL31_LIMIT) { 318 return false; 319 } 320 if (dram_region_end > dram_max_sz) { 321 return false; 322 } 323 324 return true; 325 } 326 327 static uint32_t intel_fpga_config_write(uint64_t mem, uint64_t size) 328 { 329 int i; 330 331 intel_fpga_sdm_write_all(); 332 333 if (!is_address_in_ddr_range(mem, size) || 334 is_fpga_config_buffer_full()) { 335 return INTEL_SIP_SMC_STATUS_REJECTED; 336 } 337 338 #if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5 339 intel_smmu_hps_remapper_init(&mem); 340 #endif 341 342 for (i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) { 343 int j = (i + current_buffer) % FPGA_CONFIG_BUFFER_SIZE; 344 345 if (!fpga_config_buffers[j].write_requested) { 346 fpga_config_buffers[j].addr = mem; 347 fpga_config_buffers[j].size = size; 348 fpga_config_buffers[j].size_written = 0; 349 fpga_config_buffers[j].write_requested = 1; 350 fpga_config_buffers[j].block_number = 351 blocks_submitted++; 352 fpga_config_buffers[j].subblocks_sent = 0; 353 break; 354 } 355 } 356 357 if (is_fpga_config_buffer_full()) { 358 return INTEL_SIP_SMC_STATUS_BUSY; 359 } 360 361 return INTEL_SIP_SMC_STATUS_OK; 362 } 363 364 static int is_out_of_sec_range(uint64_t reg_addr) 365 { 366 #if DEBUG 367 return 0; 368 #endif 369 370 #if PLATFORM_MODEL != PLAT_SOCFPGA_AGILEX5 371 switch (reg_addr) { 372 case(0xF8011100): /* ECCCTRL1 */ 373 case(0xF8011104): /* ECCCTRL2 */ 374 case(0xF8011110): /* ERRINTEN */ 375 case(0xF8011114): /* ERRINTENS */ 376 case(0xF8011118): /* ERRINTENR */ 377 case(0xF801111C): /* INTMODE */ 378 case(0xF8011120): /* INTSTAT */ 379 case(0xF8011124): /* DIAGINTTEST */ 380 case(0xF801112C): /* DERRADDRA */ 381 case(0xFA000000): /* SMMU SCR0 */ 382 case(0xFA000004): /* SMMU SCR1 */ 383 case(0xFA000400): /* SMMU NSCR0 */ 384 case(0xFA004000): /* SMMU SSD0_REG */ 385 case(0xFA000820): /* SMMU SMR8 */ 386 case(0xFA000c20): /* SMMU SCR8 */ 387 case(0xFA028000): /* SMMU CB8_SCTRL */ 388 case(0xFA001020): /* SMMU CBAR8 */ 389 case(0xFA028030): /* SMMU TCR_LPAE */ 390 case(0xFA028020): /* SMMU CB8_TTBR0_LOW */ 391 case(0xFA028024): /* SMMU CB8_PRRR_HIGH */ 392 case(0xFA028038): /* SMMU CB8_PRRR_MIR0 */ 393 case(0xFA02803C): /* SMMU CB8_PRRR_MIR1 */ 394 case(0xFA028010): /* SMMU_CB8)TCR2 */ 395 case(0xFFD080A4): /* SDM SMMU STREAM ID REG */ 396 case(0xFA001820): /* SMMU_CBA2R8 */ 397 case(0xFA000074): /* SMMU_STLBGSTATUS */ 398 case(0xFA0287F4): /* SMMU_CB8_TLBSTATUS */ 399 case(0xFA000060): /* SMMU_STLBIALL */ 400 case(0xFA000070): /* SMMU_STLBGSYNC */ 401 case(0xFA028618): /* CB8_TLBALL */ 402 case(0xFA0287F0): /* CB8_TLBSYNC */ 403 case(0xFFD12028): /* SDMMCGRP_CTRL */ 404 case(0xFFD12044): /* EMAC0 */ 405 case(0xFFD12048): /* EMAC1 */ 406 case(0xFFD1204C): /* EMAC2 */ 407 case(0xFFD12090): /* ECC_INT_MASK_VALUE */ 408 case(0xFFD12094): /* ECC_INT_MASK_SET */ 409 case(0xFFD12098): /* ECC_INT_MASK_CLEAR */ 410 case(0xFFD1209C): /* ECC_INTSTATUS_SERR */ 411 case(0xFFD120A0): /* ECC_INTSTATUS_DERR */ 412 case(0xFFD120C0): /* NOC_TIMEOUT */ 413 case(0xFFD120C4): /* NOC_IDLEREQ_SET */ 414 case(0xFFD120C8): /* NOC_IDLEREQ_CLR */ 415 case(0xFFD120D0): /* NOC_IDLEACK */ 416 case(0xFFD120D4): /* NOC_IDLESTATUS */ 417 case(0xFFD12200): /* BOOT_SCRATCH_COLD0 */ 418 case(0xFFD12204): /* BOOT_SCRATCH_COLD1 */ 419 case(0xFFD12220): /* BOOT_SCRATCH_COLD8 */ 420 case(0xFFD12224): /* BOOT_SCRATCH_COLD9 */ 421 return 0; 422 #else 423 switch (reg_addr) { 424 425 case(0xF8011104): /* ECCCTRL2 */ 426 case(0xFFD12028): /* SDMMCGRP_CTRL */ 427 case(0xFFD120C4): /* NOC_IDLEREQ_SET */ 428 case(0xFFD120C8): /* NOC_IDLEREQ_CLR */ 429 case(0xFFD120D0): /* NOC_IDLEACK */ 430 431 432 case(SOCFPGA_MEMCTRL(ECCCTRL1)): /* ECCCTRL1 */ 433 case(SOCFPGA_MEMCTRL(ERRINTEN)): /* ERRINTEN */ 434 case(SOCFPGA_MEMCTRL(ERRINTENS)): /* ERRINTENS */ 435 case(SOCFPGA_MEMCTRL(ERRINTENR)): /* ERRINTENR */ 436 case(SOCFPGA_MEMCTRL(INTMODE)): /* INTMODE */ 437 case(SOCFPGA_MEMCTRL(INTSTAT)): /* INTSTAT */ 438 case(SOCFPGA_MEMCTRL(DIAGINTTEST)): /* DIAGINTTEST */ 439 case(SOCFPGA_MEMCTRL(DERRADDRA)): /* DERRADDRA */ 440 441 case(SOCFPGA_ECC_QSPI(INITSTAT)): /* ECC_QSPI_INITSTAT */ 442 case(SOCFPGA_SYSMGR(EMAC_0)): /* EMAC0 */ 443 case(SOCFPGA_SYSMGR(EMAC_1)): /* EMAC1 */ 444 case(SOCFPGA_SYSMGR(EMAC_2)): /* EMAC2 */ 445 case(SOCFPGA_SYSMGR(ECC_INTMASK_VALUE)): /* ECC_INT_MASK_VALUE */ 446 case(SOCFPGA_SYSMGR(ECC_INTMASK_SET)): /* ECC_INT_MASK_SET */ 447 case(SOCFPGA_SYSMGR(ECC_INTMASK_CLR)): /* ECC_INT_MASK_CLEAR */ 448 case(SOCFPGA_SYSMGR(ECC_INTMASK_SERR)): /* ECC_INTSTATUS_SERR */ 449 case(SOCFPGA_SYSMGR(ECC_INTMASK_DERR)): /* ECC_INTSTATUS_DERR */ 450 case(SOCFPGA_SYSMGR(NOC_TIMEOUT)): /* NOC_TIMEOUT */ 451 case(SOCFPGA_SYSMGR(NOC_IDLESTATUS)): /* NOC_IDLESTATUS */ 452 case(SOCFPGA_SYSMGR(BOOT_SCRATCH_COLD_0)): /* BOOT_SCRATCH_COLD0 */ 453 case(SOCFPGA_SYSMGR(BOOT_SCRATCH_COLD_1)): /* BOOT_SCRATCH_COLD1 */ 454 case(SOCFPGA_SYSMGR(BOOT_SCRATCH_COLD_8)): /* BOOT_SCRATCH_COLD8 */ 455 case(SOCFPGA_SYSMGR(BOOT_SCRATCH_COLD_9)): /* BOOT_SCRATCH_COLD9 */ 456 #endif 457 case(SOCFPGA_ECC_QSPI(CTRL)): /* ECC_QSPI_CTRL */ 458 case(SOCFPGA_ECC_QSPI(ERRINTEN)): /* ECC_QSPI_ERRINTEN */ 459 case(SOCFPGA_ECC_QSPI(ERRINTENS)): /* ECC_QSPI_ERRINTENS */ 460 case(SOCFPGA_ECC_QSPI(ERRINTENR)): /* ECC_QSPI_ERRINTENR */ 461 case(SOCFPGA_ECC_QSPI(INTMODE)): /* ECC_QSPI_INTMODE */ 462 case(SOCFPGA_ECC_QSPI(ECC_ACCCTRL)): /* ECC_QSPI_ECC_ACCCTRL */ 463 case(SOCFPGA_ECC_QSPI(ECC_STARTACC)): /* ECC_QSPI_ECC_STARTACC */ 464 case(SOCFPGA_ECC_QSPI(ECC_WDCTRL)): /* ECC_QSPI_ECC_WDCTRL */ 465 case(SOCFPGA_ECC_QSPI(INTSTAT)): /* ECC_QSPI_INTSTAT */ 466 case(SOCFPGA_ECC_QSPI(INTTEST)): /* ECC_QSPI_INTMODE */ 467 return 0; 468 469 default: 470 break; 471 } 472 473 return -1; 474 } 475 476 /* Secure register access */ 477 uint32_t intel_secure_reg_read(uint64_t reg_addr, uint32_t *retval) 478 { 479 if (is_out_of_sec_range(reg_addr)) { 480 return INTEL_SIP_SMC_STATUS_ERROR; 481 } 482 483 *retval = mmio_read_32(reg_addr); 484 485 return INTEL_SIP_SMC_STATUS_OK; 486 } 487 488 uint32_t intel_secure_reg_write(uint64_t reg_addr, uint32_t val, 489 uint32_t *retval) 490 { 491 if (is_out_of_sec_range(reg_addr)) { 492 return INTEL_SIP_SMC_STATUS_ERROR; 493 } 494 495 switch (reg_addr) { 496 case(SOCFPGA_ECC_QSPI(INTSTAT)): /* ECC_QSPI_INTSTAT */ 497 case(SOCFPGA_ECC_QSPI(INTTEST)): /* ECC_QSPI_INTMODE */ 498 mmio_write_16(reg_addr, val); 499 break; 500 default: 501 mmio_write_32(reg_addr, val); 502 break; 503 } 504 505 return intel_secure_reg_read(reg_addr, retval); 506 } 507 508 uint32_t intel_secure_reg_update(uint64_t reg_addr, uint32_t mask, 509 uint32_t val, uint32_t *retval) 510 { 511 if (!intel_secure_reg_read(reg_addr, retval)) { 512 *retval &= ~mask; 513 *retval |= val & mask; 514 return intel_secure_reg_write(reg_addr, *retval, retval); 515 } 516 517 return INTEL_SIP_SMC_STATUS_ERROR; 518 } 519 520 /* Intel Remote System Update (RSU) services */ 521 uint64_t intel_rsu_update_address; 522 523 static uint32_t intel_rsu_status(uint64_t *respbuf, unsigned int respbuf_sz) 524 { 525 if (mailbox_rsu_status((uint32_t *)respbuf, respbuf_sz) < 0) { 526 return INTEL_SIP_SMC_RSU_ERROR; 527 } 528 529 return INTEL_SIP_SMC_STATUS_OK; 530 } 531 532 static uint32_t intel_rsu_get_device_info(uint32_t *respbuf, 533 unsigned int respbuf_sz) 534 { 535 if (mailbox_rsu_get_device_info((uint32_t *)respbuf, respbuf_sz) < 0) { 536 return INTEL_SIP_SMC_RSU_ERROR; 537 } 538 539 return INTEL_SIP_SMC_STATUS_OK; 540 } 541 542 uint32_t intel_rsu_update(uint64_t update_address) 543 { 544 if (update_address > SIZE_MAX) { 545 return INTEL_SIP_SMC_STATUS_REJECTED; 546 } 547 548 intel_rsu_update_address = update_address; 549 return INTEL_SIP_SMC_STATUS_OK; 550 } 551 552 static uint32_t intel_rsu_notify(uint32_t execution_stage) 553 { 554 if (mailbox_hps_stage_notify(execution_stage) < 0) { 555 return INTEL_SIP_SMC_RSU_ERROR; 556 } 557 558 return INTEL_SIP_SMC_STATUS_OK; 559 } 560 561 static uint32_t intel_rsu_retry_counter(uint32_t *respbuf, uint32_t respbuf_sz, 562 uint32_t *ret_stat) 563 { 564 if (mailbox_rsu_status((uint32_t *)respbuf, respbuf_sz) < 0) { 565 return INTEL_SIP_SMC_RSU_ERROR; 566 } 567 568 *ret_stat = respbuf[8]; 569 return INTEL_SIP_SMC_STATUS_OK; 570 } 571 572 static uint32_t intel_rsu_copy_dcmf_version(uint64_t dcmf_ver_1_0, 573 uint64_t dcmf_ver_3_2) 574 { 575 rsu_dcmf_ver[0] = dcmf_ver_1_0; 576 rsu_dcmf_ver[1] = dcmf_ver_1_0 >> 32; 577 rsu_dcmf_ver[2] = dcmf_ver_3_2; 578 rsu_dcmf_ver[3] = dcmf_ver_3_2 >> 32; 579 580 return INTEL_SIP_SMC_STATUS_OK; 581 } 582 583 static uint32_t intel_rsu_copy_dcmf_status(uint64_t dcmf_stat) 584 { 585 rsu_dcmf_stat[0] = 0xFFFF & (dcmf_stat >> (0 * 16)); 586 rsu_dcmf_stat[1] = 0xFFFF & (dcmf_stat >> (1 * 16)); 587 rsu_dcmf_stat[2] = 0xFFFF & (dcmf_stat >> (2 * 16)); 588 rsu_dcmf_stat[3] = 0xFFFF & (dcmf_stat >> (3 * 16)); 589 590 return INTEL_SIP_SMC_STATUS_OK; 591 } 592 593 /* Intel HWMON services */ 594 static uint32_t intel_hwmon_readtemp(uint32_t chan, uint32_t *retval) 595 { 596 if (mailbox_hwmon_readtemp(chan, retval) < 0) { 597 return INTEL_SIP_SMC_STATUS_ERROR; 598 } 599 600 return INTEL_SIP_SMC_STATUS_OK; 601 } 602 603 static uint32_t intel_hwmon_readvolt(uint32_t chan, uint32_t *retval) 604 { 605 if (mailbox_hwmon_readvolt(chan, retval) < 0) { 606 return INTEL_SIP_SMC_STATUS_ERROR; 607 } 608 609 return INTEL_SIP_SMC_STATUS_OK; 610 } 611 612 /* Mailbox services */ 613 static uint32_t intel_smc_fw_version(uint32_t *fw_version) 614 { 615 int status; 616 unsigned int resp_len = CONFIG_STATUS_WORD_SIZE; 617 uint32_t resp_data[CONFIG_STATUS_WORD_SIZE] = {0U}; 618 619 status = mailbox_send_cmd(MBOX_JOB_ID, MBOX_CONFIG_STATUS, NULL, 0U, 620 CMD_CASUAL, resp_data, &resp_len); 621 622 if (status < 0) { 623 return INTEL_SIP_SMC_STATUS_ERROR; 624 } 625 626 if (resp_len <= CONFIG_STATUS_FW_VER_OFFSET) { 627 return INTEL_SIP_SMC_STATUS_ERROR; 628 } 629 630 *fw_version = resp_data[CONFIG_STATUS_FW_VER_OFFSET] & CONFIG_STATUS_FW_VER_MASK; 631 632 return INTEL_SIP_SMC_STATUS_OK; 633 } 634 635 static uint32_t intel_mbox_send_cmd(uint32_t cmd, uint32_t *args, 636 unsigned int len, uint32_t urgent, uint64_t response, 637 unsigned int resp_len, int *mbox_status, 638 unsigned int *len_in_resp) 639 { 640 *len_in_resp = 0; 641 *mbox_status = GENERIC_RESPONSE_ERROR; 642 643 if (!is_address_in_ddr_range((uint64_t)args, sizeof(uint32_t) * len)) { 644 return INTEL_SIP_SMC_STATUS_REJECTED; 645 } 646 647 int status = mailbox_send_cmd(MBOX_JOB_ID, cmd, args, len, urgent, 648 (uint32_t *) response, &resp_len); 649 650 if (status < 0) { 651 *mbox_status = -status; 652 return INTEL_SIP_SMC_STATUS_ERROR; 653 } 654 655 *mbox_status = 0; 656 *len_in_resp = resp_len; 657 658 flush_dcache_range(response, resp_len * MBOX_WORD_BYTE); 659 660 return INTEL_SIP_SMC_STATUS_OK; 661 } 662 663 static int intel_smc_get_usercode(uint32_t *user_code) 664 { 665 int status; 666 unsigned int resp_len = sizeof(user_code) / MBOX_WORD_BYTE; 667 668 status = mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_GET_USERCODE, NULL, 669 0U, CMD_CASUAL, user_code, &resp_len); 670 671 if (status < 0) { 672 return INTEL_SIP_SMC_STATUS_ERROR; 673 } 674 675 return INTEL_SIP_SMC_STATUS_OK; 676 } 677 678 uint32_t intel_smc_service_completed(uint64_t addr, uint32_t size, 679 uint32_t mode, uint32_t *job_id, 680 uint32_t *ret_size, uint32_t *mbox_error) 681 { 682 int status = 0; 683 uint32_t resp_len = size / MBOX_WORD_BYTE; 684 685 if (resp_len > MBOX_DATA_MAX_LEN) { 686 return INTEL_SIP_SMC_STATUS_REJECTED; 687 } 688 689 if (!is_address_in_ddr_range(addr, size)) { 690 return INTEL_SIP_SMC_STATUS_REJECTED; 691 } 692 693 if (mode == SERVICE_COMPLETED_MODE_ASYNC) { 694 status = mailbox_read_response_async(job_id, 695 NULL, (uint32_t *) addr, &resp_len, 0); 696 } else { 697 status = mailbox_read_response(job_id, 698 (uint32_t *) addr, &resp_len); 699 700 if (status == MBOX_NO_RESPONSE) { 701 status = MBOX_BUSY; 702 } 703 } 704 705 if (status == MBOX_NO_RESPONSE) { 706 return INTEL_SIP_SMC_STATUS_NO_RESPONSE; 707 } 708 709 if (status == MBOX_BUSY) { 710 return INTEL_SIP_SMC_STATUS_BUSY; 711 } 712 713 *ret_size = resp_len * MBOX_WORD_BYTE; 714 flush_dcache_range(addr, *ret_size); 715 716 if (status == MBOX_RET_SDOS_DECRYPTION_ERROR_102 || 717 status == MBOX_RET_SDOS_DECRYPTION_ERROR_103) { 718 *mbox_error = -status; 719 } else if (status != MBOX_RET_OK) { 720 *mbox_error = -status; 721 return INTEL_SIP_SMC_STATUS_ERROR; 722 } 723 724 return INTEL_SIP_SMC_STATUS_OK; 725 } 726 727 /* Miscellaneous HPS services */ 728 uint32_t intel_hps_set_bridges(uint64_t enable, uint64_t mask) 729 { 730 int status = 0; 731 732 if ((enable & SOCFPGA_BRIDGE_ENABLE) != 0U) { 733 if ((enable & SOCFPGA_BRIDGE_HAS_MASK) != 0U) { 734 status = socfpga_bridges_enable((uint32_t)mask); 735 } else { 736 status = socfpga_bridges_enable(~0); 737 } 738 } else { 739 if ((enable & SOCFPGA_BRIDGE_HAS_MASK) != 0U) { 740 status = socfpga_bridges_disable((uint32_t)mask); 741 } else { 742 status = socfpga_bridges_disable(~0); 743 } 744 } 745 746 if (status < 0) { 747 return INTEL_SIP_SMC_STATUS_ERROR; 748 } 749 750 return INTEL_SIP_SMC_STATUS_OK; 751 } 752 753 /* SDM SEU Error services */ 754 static uint32_t intel_sdm_seu_err_read(uint32_t *respbuf, unsigned int respbuf_sz) 755 { 756 if (mailbox_seu_err_status(respbuf, respbuf_sz) < 0) { 757 return INTEL_SIP_SMC_SEU_ERR_READ_ERROR; 758 } 759 760 return INTEL_SIP_SMC_STATUS_OK; 761 } 762 763 /* SDM SAFE SEU Error inject services */ 764 static uint32_t intel_sdm_safe_inject_seu_err(uint32_t *command, uint32_t len) 765 { 766 if (mailbox_safe_inject_seu_err(command, len) < 0) { 767 return INTEL_SIP_SMC_SEU_ERR_READ_ERROR; 768 } 769 770 return INTEL_SIP_SMC_STATUS_OK; 771 } 772 773 #if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5 774 /* SMMU HPS Remapper */ 775 void intel_smmu_hps_remapper_init(uint64_t *mem) 776 { 777 /* Read out Bit 1 value */ 778 uint32_t remap = (mmio_read_32(SOCFPGA_SYSMGR(BOOT_SCRATCH_POR_1)) & 0x02); 779 780 if ((remap == 0x00) && (g_remapper_bypass == 0x00)) { 781 /* Update DRAM Base address for SDM SMMU */ 782 mmio_write_32(SOCFPGA_SYSMGR(SDM_BE_ARADDR_REMAP), DRAM_BASE); 783 mmio_write_32(SOCFPGA_SYSMGR(SDM_BE_AWADDR_REMAP), DRAM_BASE); 784 *mem = *mem - DRAM_BASE; 785 } else { 786 *mem = *mem - DRAM_BASE; 787 } 788 } 789 790 int intel_smmu_hps_remapper_config(uint32_t remapper_bypass) 791 { 792 /* Read out the JTAG-ID from boot scratch register */ 793 if (is_agilex5_A5F0() || is_agilex5_A5F4()) { 794 if (remapper_bypass == 0x01) { 795 g_remapper_bypass = remapper_bypass; 796 mmio_write_32(SOCFPGA_SYSMGR(SDM_BE_ARADDR_REMAP), 0); 797 mmio_write_32(SOCFPGA_SYSMGR(SDM_BE_AWADDR_REMAP), 0); 798 } 799 } 800 return INTEL_SIP_SMC_STATUS_OK; 801 } 802 #endif 803 804 #if SIP_SVC_V3 805 uint8_t sip_smc_cmd_cb_ret3(void *resp_desc, void *cmd_desc, uint32_t *ret_args) 806 { 807 uint8_t ret_args_len = 0U; 808 sdm_response_t *resp = (sdm_response_t *)resp_desc; 809 sdm_command_t *cmd = (sdm_command_t *)cmd_desc; 810 811 (void)cmd; 812 /* Returns 3 SMC arguments for SMC_RET3 */ 813 ret_args[ret_args_len++] = INTEL_SIP_SMC_STATUS_OK; 814 ret_args[ret_args_len++] = resp->err_code; 815 ret_args[ret_args_len++] = resp->resp_data[0]; 816 817 return ret_args_len; 818 } 819 820 static uintptr_t smc_ret(void *handle, uint32_t *ret_args, uint32_t ret_args_len) 821 { 822 switch (ret_args_len) { 823 case SMC_RET_ARGS_ONE: 824 SMC_RET1(handle, ret_args[0]); 825 break; 826 827 case SMC_RET_ARGS_TWO: 828 SMC_RET2(handle, ret_args[0], ret_args[1]); 829 break; 830 831 case SMC_RET_ARGS_THREE: 832 SMC_RET3(handle, ret_args[0], ret_args[1], ret_args[2]); 833 break; 834 835 case SMC_RET_ARGS_FOUR: 836 SMC_RET4(handle, ret_args[0], ret_args[1], ret_args[2], ret_args[3]); 837 break; 838 839 case SMC_RET_ARGS_FIVE: 840 SMC_RET5(handle, ret_args[0], ret_args[1], ret_args[2], ret_args[3], ret_args[4]); 841 break; 842 843 default: 844 SMC_RET1(handle, INTEL_SIP_SMC_STATUS_ERROR); 845 break; 846 } 847 } 848 849 /* 850 * This function is responsible for handling all SiP SVC V3 calls from the 851 * non-secure world. 852 */ 853 static uintptr_t sip_smc_handler_v3(uint32_t smc_fid, 854 u_register_t x1, 855 u_register_t x2, 856 u_register_t x3, 857 u_register_t x4, 858 void *cookie, 859 void *handle, 860 u_register_t flags) 861 { 862 int status = 0; 863 864 VERBOSE("MBOX: SVC-V3: x0 0x%x, x1 0x%lx, x2 0x%lx, x3 0x%lx, x4 0x%lx\n", 865 smc_fid, x1, x2, x3, x4); 866 867 switch (smc_fid) { 868 case ALTERA_SIP_SMC_ASYNC_RESP_POLL: 869 { 870 uint32_t ret_args[8] = {0}; /* X0 to X7 return arguments */ 871 uint32_t ret_args_len; 872 873 status = mailbox_response_poll_v3(GET_CLIENT_ID(x1), 874 GET_JOB_ID(x1), 875 ret_args, 876 &ret_args_len); 877 /* Always reserve [0] index for command status. */ 878 ret_args[0] = status; 879 880 /* Return SMC call based on the number of return arguments */ 881 return smc_ret(handle, ret_args, ret_args_len); 882 } 883 884 case ALTERA_SIP_SMC_ASYNC_RESP_POLL_ON_INTR: 885 { 886 uint8_t client_id = 0U; 887 uint8_t job_id = 0U; 888 uint64_t trans_id_bitmap[4] = {0U}; 889 890 status = mailbox_response_poll_on_intr_v3(&client_id, 891 &job_id, 892 trans_id_bitmap); 893 894 SMC_RET5(handle, status, trans_id_bitmap[0], trans_id_bitmap[1], 895 trans_id_bitmap[2], trans_id_bitmap[3]); 896 break; 897 } 898 899 case ALTERA_SIP_SMC_ASYNC_HWMON_READVOLT: 900 case ALTERA_SIP_SMC_ASYNC_HWMON_READTEMP: 901 { 902 uint32_t channel = (uint32_t)x2; 903 uint32_t mbox_cmd = ((smc_fid == ALTERA_SIP_SMC_ASYNC_HWMON_READVOLT) ? 904 MBOX_HWMON_READVOLT : MBOX_HWMON_READTEMP); 905 906 status = mailbox_send_cmd_async_v3(GET_CLIENT_ID(x1), 907 GET_JOB_ID(x1), 908 mbox_cmd, 909 &channel, 910 1U, 911 MBOX_CMD_FLAG_CASUAL, 912 sip_smc_cmd_cb_ret3, 913 NULL, 914 0); 915 916 SMC_RET1(handle, status); 917 } 918 919 default: 920 return socfpga_sip_handler(smc_fid, x1, x2, x3, x4, 921 cookie, handle, flags); 922 } /* switch (smc_fid) */ 923 } 924 #endif 925 926 /* 927 * This function is responsible for handling all SiP calls from the NS world 928 */ 929 930 uintptr_t sip_smc_handler_v1(uint32_t smc_fid, 931 u_register_t x1, 932 u_register_t x2, 933 u_register_t x3, 934 u_register_t x4, 935 void *cookie, 936 void *handle, 937 u_register_t flags) 938 { 939 uint32_t retval = 0, completed_addr[3]; 940 uint32_t retval2 = 0; 941 uint32_t mbox_error = 0; 942 uint32_t err_states = 0; 943 uint64_t retval64, rsu_respbuf[9]; 944 uint32_t seu_respbuf[3]; 945 int status = INTEL_SIP_SMC_STATUS_OK; 946 int mbox_status; 947 unsigned int len_in_resp; 948 u_register_t x5, x6, x7; 949 950 switch (smc_fid) { 951 case SIP_SVC_UID: 952 /* Return UID to the caller */ 953 SMC_UUID_RET(handle, intl_svc_uid); 954 955 case INTEL_SIP_SMC_FPGA_CONFIG_ISDONE: 956 status = intel_mailbox_fpga_config_isdone(&err_states); 957 SMC_RET4(handle, status, err_states, 0, 0); 958 959 case INTEL_SIP_SMC_FPGA_CONFIG_GET_MEM: 960 SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK, 961 INTEL_SIP_SMC_FPGA_CONFIG_ADDR, 962 INTEL_SIP_SMC_FPGA_CONFIG_SIZE - 963 INTEL_SIP_SMC_FPGA_CONFIG_ADDR); 964 965 case INTEL_SIP_SMC_FPGA_CONFIG_START: 966 status = intel_fpga_config_start(x1); 967 SMC_RET4(handle, status, 0, 0, 0); 968 969 case INTEL_SIP_SMC_FPGA_CONFIG_WRITE: 970 status = intel_fpga_config_write(x1, x2); 971 SMC_RET4(handle, status, 0, 0, 0); 972 973 case INTEL_SIP_SMC_FPGA_CONFIG_COMPLETED_WRITE: 974 status = intel_fpga_config_completed_write(completed_addr, 975 &retval, &rcv_id); 976 switch (retval) { 977 case 1: 978 SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK, 979 completed_addr[0], 0, 0); 980 981 case 2: 982 SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK, 983 completed_addr[0], 984 completed_addr[1], 0); 985 986 case 3: 987 SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK, 988 completed_addr[0], 989 completed_addr[1], 990 completed_addr[2]); 991 992 case 0: 993 SMC_RET4(handle, status, 0, 0, 0); 994 995 default: 996 mailbox_clear_response(); 997 SMC_RET1(handle, INTEL_SIP_SMC_STATUS_ERROR); 998 } 999 1000 case INTEL_SIP_SMC_REG_READ: 1001 status = intel_secure_reg_read(x1, &retval); 1002 SMC_RET3(handle, status, retval, x1); 1003 1004 case INTEL_SIP_SMC_REG_WRITE: 1005 status = intel_secure_reg_write(x1, (uint32_t)x2, &retval); 1006 SMC_RET3(handle, status, retval, x1); 1007 1008 case INTEL_SIP_SMC_REG_UPDATE: 1009 status = intel_secure_reg_update(x1, (uint32_t)x2, 1010 (uint32_t)x3, &retval); 1011 SMC_RET3(handle, status, retval, x1); 1012 1013 case INTEL_SIP_SMC_RSU_STATUS: 1014 status = intel_rsu_status(rsu_respbuf, 1015 ARRAY_SIZE(rsu_respbuf)); 1016 if (status) { 1017 SMC_RET1(handle, status); 1018 } else { 1019 SMC_RET4(handle, rsu_respbuf[0], rsu_respbuf[1], 1020 rsu_respbuf[2], rsu_respbuf[3]); 1021 } 1022 1023 case INTEL_SIP_SMC_RSU_UPDATE: 1024 status = intel_rsu_update(x1); 1025 SMC_RET1(handle, status); 1026 1027 case INTEL_SIP_SMC_RSU_NOTIFY: 1028 status = intel_rsu_notify(x1); 1029 SMC_RET1(handle, status); 1030 1031 case INTEL_SIP_SMC_RSU_RETRY_COUNTER: 1032 status = intel_rsu_retry_counter((uint32_t *)rsu_respbuf, 1033 ARRAY_SIZE(rsu_respbuf), &retval); 1034 if (status) { 1035 SMC_RET1(handle, status); 1036 } else { 1037 SMC_RET2(handle, status, retval); 1038 } 1039 1040 case INTEL_SIP_SMC_RSU_DCMF_VERSION: 1041 SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK, 1042 ((uint64_t)rsu_dcmf_ver[1] << 32) | rsu_dcmf_ver[0], 1043 ((uint64_t)rsu_dcmf_ver[3] << 32) | rsu_dcmf_ver[2]); 1044 1045 case INTEL_SIP_SMC_RSU_COPY_DCMF_VERSION: 1046 status = intel_rsu_copy_dcmf_version(x1, x2); 1047 SMC_RET1(handle, status); 1048 1049 case INTEL_SIP_SMC_RSU_GET_DEVICE_INFO: 1050 status = intel_rsu_get_device_info((uint32_t *)rsu_respbuf, 1051 ARRAY_SIZE(rsu_respbuf)); 1052 if (status) { 1053 SMC_RET1(handle, status); 1054 } else { 1055 SMC_RET5(handle, status, rsu_respbuf[0], rsu_respbuf[1], 1056 rsu_respbuf[2], rsu_respbuf[3]); 1057 } 1058 1059 case INTEL_SIP_SMC_RSU_DCMF_STATUS: 1060 SMC_RET2(handle, INTEL_SIP_SMC_STATUS_OK, 1061 ((uint64_t)rsu_dcmf_stat[3] << 48) | 1062 ((uint64_t)rsu_dcmf_stat[2] << 32) | 1063 ((uint64_t)rsu_dcmf_stat[1] << 16) | 1064 rsu_dcmf_stat[0]); 1065 1066 case INTEL_SIP_SMC_RSU_COPY_DCMF_STATUS: 1067 status = intel_rsu_copy_dcmf_status(x1); 1068 SMC_RET1(handle, status); 1069 1070 case INTEL_SIP_SMC_RSU_MAX_RETRY: 1071 SMC_RET2(handle, INTEL_SIP_SMC_STATUS_OK, rsu_max_retry); 1072 1073 case INTEL_SIP_SMC_RSU_COPY_MAX_RETRY: 1074 rsu_max_retry = x1; 1075 SMC_RET1(handle, INTEL_SIP_SMC_STATUS_OK); 1076 1077 case INTEL_SIP_SMC_ECC_DBE: 1078 status = intel_ecc_dbe_notification(x1); 1079 SMC_RET1(handle, status); 1080 1081 case INTEL_SIP_SMC_SERVICE_COMPLETED: 1082 status = intel_smc_service_completed(x1, x2, x3, &rcv_id, 1083 &len_in_resp, &mbox_error); 1084 SMC_RET4(handle, status, mbox_error, x1, len_in_resp); 1085 1086 case INTEL_SIP_SMC_FIRMWARE_VERSION: 1087 status = intel_smc_fw_version(&retval); 1088 SMC_RET2(handle, status, retval); 1089 1090 case INTEL_SIP_SMC_MBOX_SEND_CMD: 1091 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1092 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1093 status = intel_mbox_send_cmd(x1, (uint32_t *)x2, x3, x4, x5, x6, 1094 &mbox_status, &len_in_resp); 1095 SMC_RET3(handle, status, mbox_status, len_in_resp); 1096 1097 case INTEL_SIP_SMC_GET_USERCODE: 1098 status = intel_smc_get_usercode(&retval); 1099 SMC_RET2(handle, status, retval); 1100 1101 case INTEL_SIP_SMC_FCS_CRYPTION: 1102 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1103 1104 if (x1 == FCS_MODE_DECRYPT) { 1105 status = intel_fcs_decryption(x2, x3, x4, x5, &send_id); 1106 } else if (x1 == FCS_MODE_ENCRYPT) { 1107 status = intel_fcs_encryption(x2, x3, x4, x5, &send_id); 1108 } else { 1109 status = INTEL_SIP_SMC_STATUS_REJECTED; 1110 } 1111 1112 SMC_RET3(handle, status, x4, x5); 1113 1114 case INTEL_SIP_SMC_FCS_CRYPTION_EXT: 1115 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1116 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1117 x7 = SMC_GET_GP(handle, CTX_GPREG_X7); 1118 1119 if (x3 == FCS_MODE_DECRYPT) { 1120 status = intel_fcs_decryption_ext(x1, x2, x4, x5, x6, 1121 (uint32_t *) &x7, &mbox_error); 1122 } else if (x3 == FCS_MODE_ENCRYPT) { 1123 status = intel_fcs_encryption_ext(x1, x2, x4, x5, x6, 1124 (uint32_t *) &x7, &mbox_error); 1125 } else { 1126 status = INTEL_SIP_SMC_STATUS_REJECTED; 1127 } 1128 1129 SMC_RET4(handle, status, mbox_error, x6, x7); 1130 1131 case INTEL_SIP_SMC_FCS_RANDOM_NUMBER: 1132 status = intel_fcs_random_number_gen(x1, &retval64, 1133 &mbox_error); 1134 SMC_RET4(handle, status, mbox_error, x1, retval64); 1135 1136 case INTEL_SIP_SMC_FCS_RANDOM_NUMBER_EXT: 1137 status = intel_fcs_random_number_gen_ext(x1, x2, x3, 1138 &send_id); 1139 SMC_RET1(handle, status); 1140 1141 case INTEL_SIP_SMC_FCS_SEND_CERTIFICATE: 1142 status = intel_fcs_send_cert(x1, x2, &send_id); 1143 SMC_RET1(handle, status); 1144 1145 case INTEL_SIP_SMC_FCS_GET_PROVISION_DATA: 1146 status = intel_fcs_get_provision_data(&send_id); 1147 SMC_RET1(handle, status); 1148 1149 case INTEL_SIP_SMC_FCS_CNTR_SET_PREAUTH: 1150 status = intel_fcs_cntr_set_preauth(x1, x2, x3, 1151 &mbox_error); 1152 SMC_RET2(handle, status, mbox_error); 1153 1154 case INTEL_SIP_SMC_HPS_SET_BRIDGES: 1155 status = intel_hps_set_bridges(x1, x2); 1156 SMC_RET1(handle, status); 1157 1158 case INTEL_SIP_SMC_HWMON_READTEMP: 1159 status = intel_hwmon_readtemp(x1, &retval); 1160 SMC_RET2(handle, status, retval); 1161 1162 case INTEL_SIP_SMC_HWMON_READVOLT: 1163 status = intel_hwmon_readvolt(x1, &retval); 1164 SMC_RET2(handle, status, retval); 1165 1166 case INTEL_SIP_SMC_FCS_PSGSIGMA_TEARDOWN: 1167 status = intel_fcs_sigma_teardown(x1, &mbox_error); 1168 SMC_RET2(handle, status, mbox_error); 1169 1170 case INTEL_SIP_SMC_FCS_CHIP_ID: 1171 status = intel_fcs_chip_id(&retval, &retval2, &mbox_error); 1172 SMC_RET4(handle, status, mbox_error, retval, retval2); 1173 1174 case INTEL_SIP_SMC_FCS_ATTESTATION_SUBKEY: 1175 status = intel_fcs_attestation_subkey(x1, x2, x3, 1176 (uint32_t *) &x4, &mbox_error); 1177 SMC_RET4(handle, status, mbox_error, x3, x4); 1178 1179 case INTEL_SIP_SMC_FCS_ATTESTATION_MEASUREMENTS: 1180 status = intel_fcs_get_measurement(x1, x2, x3, 1181 (uint32_t *) &x4, &mbox_error); 1182 SMC_RET4(handle, status, mbox_error, x3, x4); 1183 1184 case INTEL_SIP_SMC_FCS_GET_ATTESTATION_CERT: 1185 status = intel_fcs_get_attestation_cert(x1, x2, 1186 (uint32_t *) &x3, &mbox_error); 1187 SMC_RET4(handle, status, mbox_error, x2, x3); 1188 1189 case INTEL_SIP_SMC_FCS_CREATE_CERT_ON_RELOAD: 1190 status = intel_fcs_create_cert_on_reload(x1, &mbox_error); 1191 SMC_RET2(handle, status, mbox_error); 1192 1193 case INTEL_SIP_SMC_FCS_OPEN_CS_SESSION: 1194 status = intel_fcs_open_crypto_service_session(&retval, &mbox_error); 1195 SMC_RET3(handle, status, mbox_error, retval); 1196 1197 case INTEL_SIP_SMC_FCS_CLOSE_CS_SESSION: 1198 status = intel_fcs_close_crypto_service_session(x1, &mbox_error); 1199 SMC_RET2(handle, status, mbox_error); 1200 1201 case INTEL_SIP_SMC_FCS_IMPORT_CS_KEY: 1202 status = intel_fcs_import_crypto_service_key(x1, x2, &send_id); 1203 SMC_RET1(handle, status); 1204 1205 case INTEL_SIP_SMC_FCS_EXPORT_CS_KEY: 1206 status = intel_fcs_export_crypto_service_key(x1, x2, x3, 1207 (uint32_t *) &x4, &mbox_error); 1208 SMC_RET4(handle, status, mbox_error, x3, x4); 1209 1210 case INTEL_SIP_SMC_FCS_REMOVE_CS_KEY: 1211 status = intel_fcs_remove_crypto_service_key(x1, x2, 1212 &mbox_error); 1213 SMC_RET2(handle, status, mbox_error); 1214 1215 case INTEL_SIP_SMC_FCS_GET_CS_KEY_INFO: 1216 status = intel_fcs_get_crypto_service_key_info(x1, x2, x3, 1217 (uint32_t *) &x4, &mbox_error); 1218 SMC_RET4(handle, status, mbox_error, x3, x4); 1219 1220 case INTEL_SIP_SMC_FCS_GET_DIGEST_INIT: 1221 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1222 status = intel_fcs_get_digest_init(x1, x2, x3, 1223 x4, x5, &mbox_error); 1224 SMC_RET2(handle, status, mbox_error); 1225 1226 case INTEL_SIP_SMC_FCS_GET_DIGEST_UPDATE: 1227 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1228 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1229 status = intel_fcs_get_digest_update_finalize(x1, x2, x3, 1230 x4, x5, (uint32_t *) &x6, false, 1231 &mbox_error); 1232 SMC_RET4(handle, status, mbox_error, x5, x6); 1233 1234 case INTEL_SIP_SMC_FCS_GET_DIGEST_FINALIZE: 1235 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1236 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1237 status = intel_fcs_get_digest_update_finalize(x1, x2, x3, 1238 x4, x5, (uint32_t *) &x6, true, 1239 &mbox_error); 1240 SMC_RET4(handle, status, mbox_error, x5, x6); 1241 1242 case INTEL_SIP_SMC_FCS_GET_DIGEST_SMMU_UPDATE: 1243 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1244 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1245 status = intel_fcs_get_digest_smmu_update_finalize(x1, x2, x3, 1246 x4, x5, (uint32_t *) &x6, false, 1247 &mbox_error, &send_id); 1248 SMC_RET4(handle, status, mbox_error, x5, x6); 1249 1250 case INTEL_SIP_SMC_FCS_GET_DIGEST_SMMU_FINALIZE: 1251 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1252 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1253 status = intel_fcs_get_digest_smmu_update_finalize(x1, x2, x3, 1254 x4, x5, (uint32_t *) &x6, true, 1255 &mbox_error, &send_id); 1256 SMC_RET4(handle, status, mbox_error, x5, x6); 1257 1258 case INTEL_SIP_SMC_FCS_MAC_VERIFY_INIT: 1259 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1260 status = intel_fcs_mac_verify_init(x1, x2, x3, 1261 x4, x5, &mbox_error); 1262 SMC_RET2(handle, status, mbox_error); 1263 1264 case INTEL_SIP_SMC_FCS_MAC_VERIFY_UPDATE: 1265 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1266 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1267 x7 = SMC_GET_GP(handle, CTX_GPREG_X7); 1268 status = intel_fcs_mac_verify_update_finalize(x1, x2, x3, 1269 x4, x5, (uint32_t *) &x6, x7, 1270 false, &mbox_error); 1271 SMC_RET4(handle, status, mbox_error, x5, x6); 1272 1273 case INTEL_SIP_SMC_FCS_MAC_VERIFY_FINALIZE: 1274 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1275 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1276 x7 = SMC_GET_GP(handle, CTX_GPREG_X7); 1277 status = intel_fcs_mac_verify_update_finalize(x1, x2, x3, 1278 x4, x5, (uint32_t *) &x6, x7, 1279 true, &mbox_error); 1280 SMC_RET4(handle, status, mbox_error, x5, x6); 1281 1282 case INTEL_SIP_SMC_FCS_MAC_VERIFY_SMMU_UPDATE: 1283 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1284 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1285 x7 = SMC_GET_GP(handle, CTX_GPREG_X7); 1286 status = intel_fcs_mac_verify_smmu_update_finalize(x1, x2, x3, 1287 x4, x5, (uint32_t *) &x6, x7, 1288 false, &mbox_error, &send_id); 1289 SMC_RET4(handle, status, mbox_error, x5, x6); 1290 1291 case INTEL_SIP_SMC_FCS_MAC_VERIFY_SMMU_FINALIZE: 1292 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1293 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1294 x7 = SMC_GET_GP(handle, CTX_GPREG_X7); 1295 status = intel_fcs_mac_verify_smmu_update_finalize(x1, x2, x3, 1296 x4, x5, (uint32_t *) &x6, x7, 1297 true, &mbox_error, &send_id); 1298 SMC_RET4(handle, status, mbox_error, x5, x6); 1299 1300 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIGN_INIT: 1301 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1302 status = intel_fcs_ecdsa_sha2_data_sign_init(x1, x2, x3, 1303 x4, x5, &mbox_error); 1304 SMC_RET2(handle, status, mbox_error); 1305 1306 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIGN_UPDATE: 1307 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1308 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1309 status = intel_fcs_ecdsa_sha2_data_sign_update_finalize(x1, x2, 1310 x3, x4, x5, (uint32_t *) &x6, false, 1311 &mbox_error); 1312 SMC_RET4(handle, status, mbox_error, x5, x6); 1313 1314 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIGN_FINALIZE: 1315 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1316 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1317 status = intel_fcs_ecdsa_sha2_data_sign_update_finalize(x1, x2, 1318 x3, x4, x5, (uint32_t *) &x6, true, 1319 &mbox_error); 1320 SMC_RET4(handle, status, mbox_error, x5, x6); 1321 1322 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIGN_SMMU_UPDATE: 1323 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1324 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1325 status = intel_fcs_ecdsa_sha2_data_sign_smmu_update_finalize(x1, 1326 x2, x3, x4, x5, (uint32_t *) &x6, false, 1327 &mbox_error, &send_id); 1328 SMC_RET4(handle, status, mbox_error, x5, x6); 1329 1330 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIGN_SMMU_FINALIZE: 1331 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1332 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1333 status = intel_fcs_ecdsa_sha2_data_sign_smmu_update_finalize(x1, 1334 x2, x3, x4, x5, (uint32_t *) &x6, true, 1335 &mbox_error, &send_id); 1336 SMC_RET4(handle, status, mbox_error, x5, x6); 1337 1338 case INTEL_SIP_SMC_FCS_ECDSA_HASH_SIGN_INIT: 1339 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1340 status = intel_fcs_ecdsa_hash_sign_init(x1, x2, x3, 1341 x4, x5, &mbox_error); 1342 SMC_RET2(handle, status, mbox_error); 1343 1344 case INTEL_SIP_SMC_FCS_ECDSA_HASH_SIGN_FINALIZE: 1345 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1346 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1347 status = intel_fcs_ecdsa_hash_sign_finalize(x1, x2, x3, 1348 x4, x5, (uint32_t *) &x6, &mbox_error); 1349 SMC_RET4(handle, status, mbox_error, x5, x6); 1350 1351 case INTEL_SIP_SMC_FCS_ECDSA_HASH_SIG_VERIFY_INIT: 1352 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1353 status = intel_fcs_ecdsa_hash_sig_verify_init(x1, x2, x3, 1354 x4, x5, &mbox_error); 1355 SMC_RET2(handle, status, mbox_error); 1356 1357 case INTEL_SIP_SMC_FCS_ECDSA_HASH_SIG_VERIFY_FINALIZE: 1358 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1359 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1360 status = intel_fcs_ecdsa_hash_sig_verify_finalize(x1, x2, x3, 1361 x4, x5, (uint32_t *) &x6, &mbox_error); 1362 SMC_RET4(handle, status, mbox_error, x5, x6); 1363 1364 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIG_VERIFY_INIT: 1365 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1366 status = intel_fcs_ecdsa_sha2_data_sig_verify_init(x1, x2, x3, 1367 x4, x5, &mbox_error); 1368 SMC_RET2(handle, status, mbox_error); 1369 1370 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIG_VERIFY_UPDATE: 1371 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1372 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1373 x7 = SMC_GET_GP(handle, CTX_GPREG_X7); 1374 status = intel_fcs_ecdsa_sha2_data_sig_verify_update_finalize( 1375 x1, x2, x3, x4, x5, (uint32_t *) &x6, 1376 x7, false, &mbox_error); 1377 SMC_RET4(handle, status, mbox_error, x5, x6); 1378 1379 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIG_VERIFY_SMMU_UPDATE: 1380 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1381 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1382 x7 = SMC_GET_GP(handle, CTX_GPREG_X7); 1383 status = intel_fcs_ecdsa_sha2_data_sig_verify_smmu_update_finalize( 1384 x1, x2, x3, x4, x5, (uint32_t *) &x6, 1385 x7, false, &mbox_error, &send_id); 1386 SMC_RET4(handle, status, mbox_error, x5, x6); 1387 1388 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIG_VERIFY_SMMU_FINALIZE: 1389 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1390 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1391 x7 = SMC_GET_GP(handle, CTX_GPREG_X7); 1392 status = intel_fcs_ecdsa_sha2_data_sig_verify_smmu_update_finalize( 1393 x1, x2, x3, x4, x5, (uint32_t *) &x6, 1394 x7, true, &mbox_error, &send_id); 1395 SMC_RET4(handle, status, mbox_error, x5, x6); 1396 1397 case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIG_VERIFY_FINALIZE: 1398 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1399 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1400 x7 = SMC_GET_GP(handle, CTX_GPREG_X7); 1401 status = intel_fcs_ecdsa_sha2_data_sig_verify_update_finalize( 1402 x1, x2, x3, x4, x5, (uint32_t *) &x6, 1403 x7, true, &mbox_error); 1404 SMC_RET4(handle, status, mbox_error, x5, x6); 1405 1406 case INTEL_SIP_SMC_FCS_ECDSA_GET_PUBKEY_INIT: 1407 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1408 status = intel_fcs_ecdsa_get_pubkey_init(x1, x2, x3, 1409 x4, x5, &mbox_error); 1410 SMC_RET2(handle, status, mbox_error); 1411 1412 case INTEL_SIP_SMC_FCS_ECDSA_GET_PUBKEY_FINALIZE: 1413 status = intel_fcs_ecdsa_get_pubkey_finalize(x1, x2, x3, 1414 (uint32_t *) &x4, &mbox_error); 1415 SMC_RET4(handle, status, mbox_error, x3, x4); 1416 1417 case INTEL_SIP_SMC_FCS_ECDH_REQUEST_INIT: 1418 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1419 status = intel_fcs_ecdh_request_init(x1, x2, x3, 1420 x4, x5, &mbox_error); 1421 SMC_RET2(handle, status, mbox_error); 1422 1423 case INTEL_SIP_SMC_FCS_ECDH_REQUEST_FINALIZE: 1424 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1425 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1426 status = intel_fcs_ecdh_request_finalize(x1, x2, x3, 1427 x4, x5, (uint32_t *) &x6, &mbox_error); 1428 SMC_RET4(handle, status, mbox_error, x5, x6); 1429 1430 case INTEL_SIP_SMC_FCS_AES_CRYPT_INIT: 1431 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1432 status = intel_fcs_aes_crypt_init(x1, x2, x3, x4, x5, 1433 &mbox_error); 1434 SMC_RET2(handle, status, mbox_error); 1435 1436 case INTEL_SIP_SMC_FCS_AES_CRYPT_UPDATE: 1437 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1438 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1439 status = intel_fcs_aes_crypt_update_finalize(x1, x2, x3, x4, 1440 x5, x6, false, &send_id); 1441 SMC_RET1(handle, status); 1442 1443 case INTEL_SIP_SMC_FCS_AES_CRYPT_FINALIZE: 1444 x5 = SMC_GET_GP(handle, CTX_GPREG_X5); 1445 x6 = SMC_GET_GP(handle, CTX_GPREG_X6); 1446 status = intel_fcs_aes_crypt_update_finalize(x1, x2, x3, x4, 1447 x5, x6, true, &send_id); 1448 SMC_RET1(handle, status); 1449 1450 #if PLATFORM_MODEL == PLAT_SOCFPGA_AGILEX5 1451 case INTEL_SIP_SMC_FCS_SDM_REMAPPER_CONFIG: 1452 status = intel_smmu_hps_remapper_config(x1); 1453 SMC_RET1(handle, status); 1454 #endif 1455 1456 case INTEL_SIP_SMC_GET_ROM_PATCH_SHA384: 1457 status = intel_fcs_get_rom_patch_sha384(x1, &retval64, 1458 &mbox_error); 1459 SMC_RET4(handle, status, mbox_error, x1, retval64); 1460 1461 case INTEL_SIP_SMC_SVC_VERSION: 1462 SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK, 1463 SIP_SVC_VERSION_MAJOR, 1464 SIP_SVC_VERSION_MINOR); 1465 1466 case INTEL_SIP_SMC_SEU_ERR_STATUS: 1467 status = intel_sdm_seu_err_read(seu_respbuf, 1468 ARRAY_SIZE(seu_respbuf)); 1469 if (status) { 1470 SMC_RET1(handle, status); 1471 } else { 1472 SMC_RET3(handle, seu_respbuf[0], seu_respbuf[1], seu_respbuf[2]); 1473 } 1474 1475 case INTEL_SIP_SMC_SAFE_INJECT_SEU_ERR: 1476 status = intel_sdm_safe_inject_seu_err((uint32_t *)&x1, (uint32_t)x2); 1477 SMC_RET1(handle, status); 1478 1479 default: 1480 return socfpga_sip_handler(smc_fid, x1, x2, x3, x4, 1481 cookie, handle, flags); 1482 } 1483 } 1484 1485 uintptr_t sip_smc_handler(uint32_t smc_fid, 1486 u_register_t x1, 1487 u_register_t x2, 1488 u_register_t x3, 1489 u_register_t x4, 1490 void *cookie, 1491 void *handle, 1492 u_register_t flags) 1493 { 1494 uint32_t cmd = smc_fid & INTEL_SIP_SMC_CMD_MASK; 1495 1496 if (cmd >= INTEL_SIP_SMC_CMD_V2_RANGE_BEGIN && 1497 cmd <= INTEL_SIP_SMC_CMD_V2_RANGE_END) { 1498 return sip_smc_handler_v2(smc_fid, x1, x2, x3, x4, 1499 cookie, handle, flags); 1500 } 1501 #if SIP_SVC_V3 1502 else if ((cmd >= INTEL_SIP_SMC_CMD_V3_RANGE_BEGIN) && 1503 (cmd <= INTEL_SIP_SMC_CMD_V3_RANGE_END)) { 1504 uintptr_t ret = sip_smc_handler_v3(smc_fid, x1, x2, x3, x4, 1505 cookie, handle, flags); 1506 return ret; 1507 } 1508 #endif 1509 else { 1510 return sip_smc_handler_v1(smc_fid, x1, x2, x3, x4, 1511 cookie, handle, flags); 1512 } 1513 } 1514 1515 DECLARE_RT_SVC( 1516 socfpga_sip_svc, 1517 OEN_SIP_START, 1518 OEN_SIP_END, 1519 SMC_TYPE_FAST, 1520 NULL, 1521 sip_smc_handler 1522 ); 1523 1524 DECLARE_RT_SVC( 1525 socfpga_sip_svc_std, 1526 OEN_SIP_START, 1527 OEN_SIP_END, 1528 SMC_TYPE_YIELD, 1529 NULL, 1530 sip_smc_handler 1531 ); 1532