Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 1 | /* |
Abdul Halim, Muhammad Hadi Asyrafi | 461f544 | 2020-07-03 13:22:09 +0800 | [diff] [blame] | 2 | * Copyright (c) 2019-2022, ARM Limited and Contributors. All rights reserved. |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <common/debug.h> |
| 9 | #include <common/runtime_svc.h> |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 10 | #include <lib/mmio.h> |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 11 | #include <tools_share/uuid.h> |
| 12 | |
Sieu Mun Tang | 9f22cbf | 2022-03-02 11:04:09 +0800 | [diff] [blame] | 13 | #include "socfpga_fcs.h" |
Hadi Asyrafi | 6f8a2b2 | 2019-10-23 18:34:14 +0800 | [diff] [blame] | 14 | #include "socfpga_mailbox.h" |
Hadi Asyrafi | 36a9f30 | 2019-12-24 10:42:52 +0800 | [diff] [blame] | 15 | #include "socfpga_reset_manager.h" |
Hadi Asyrafi | ab1132f | 2019-10-22 10:31:45 +0800 | [diff] [blame] | 16 | #include "socfpga_sip_svc.h" |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 17 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 18 | |
| 19 | /* Total buffer the driver can hold */ |
| 20 | #define FPGA_CONFIG_BUFFER_SIZE 4 |
| 21 | |
Abdul Halim, Muhammad Hadi Asyrafi | 20a07f3 | 2020-05-18 11:16:48 +0800 | [diff] [blame] | 22 | static int current_block, current_buffer; |
Abdul Halim, Muhammad Hadi Asyrafi | b251c33 | 2020-05-29 12:13:17 +0800 | [diff] [blame] | 23 | static int read_block, max_blocks; |
Abdul Halim, Muhammad Hadi Asyrafi | 20a07f3 | 2020-05-18 11:16:48 +0800 | [diff] [blame] | 24 | static uint32_t send_id, rcv_id; |
| 25 | static uint32_t bytes_per_block, blocks_submitted; |
Sieu Mun Tang | 5406498 | 2022-04-28 22:40:58 +0800 | [diff] [blame] | 26 | static bool bridge_disable; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 27 | |
Sieu Mun Tang | e6d5de9 | 2022-04-28 22:21:01 +0800 | [diff] [blame] | 28 | /* RSU static variables */ |
Chee Hong Ang | 2cfd8ec | 2020-05-13 11:44:04 +0800 | [diff] [blame] | 29 | static uint32_t rsu_dcmf_ver[4] = {0}; |
| 30 | |
Chee Hong Ang | 681631b | 2020-07-01 14:22:25 +0800 | [diff] [blame] | 31 | /* RSU Max Retry */ |
| 32 | static uint32_t rsu_max_retry; |
Sieu Mun Tang | e6d5de9 | 2022-04-28 22:21:01 +0800 | [diff] [blame] | 33 | static uint16_t rsu_dcmf_stat[4] = {0}; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 34 | |
| 35 | /* SiP Service UUID */ |
| 36 | DEFINE_SVC_UUID2(intl_svc_uid, |
| 37 | 0xa85273b0, 0xe85a, 0x4862, 0xa6, 0x2a, |
| 38 | 0xfa, 0x88, 0x88, 0x17, 0x68, 0x81); |
| 39 | |
Hadi Asyrafi | cee6aa9 | 2019-12-17 15:25:04 +0800 | [diff] [blame] | 40 | static uint64_t socfpga_sip_handler(uint32_t smc_fid, |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 41 | uint64_t x1, |
| 42 | uint64_t x2, |
| 43 | uint64_t x3, |
| 44 | uint64_t x4, |
| 45 | void *cookie, |
| 46 | void *handle, |
| 47 | uint64_t flags) |
| 48 | { |
| 49 | ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); |
| 50 | SMC_RET1(handle, SMC_UNK); |
| 51 | } |
| 52 | |
| 53 | struct fpga_config_info fpga_config_buffers[FPGA_CONFIG_BUFFER_SIZE]; |
| 54 | |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 55 | static int intel_fpga_sdm_write_buffer(struct fpga_config_info *buffer) |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 56 | { |
Abdul Halim, Muhammad Hadi Asyrafi | d84bfef | 2020-02-25 16:28:10 +0800 | [diff] [blame] | 57 | uint32_t args[3]; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 58 | |
| 59 | while (max_blocks > 0 && buffer->size > buffer->size_written) { |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 60 | args[0] = (1<<8); |
| 61 | args[1] = buffer->addr + buffer->size_written; |
| 62 | if (buffer->size - buffer->size_written <= bytes_per_block) { |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 63 | args[2] = buffer->size - buffer->size_written; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 64 | current_buffer++; |
| 65 | current_buffer %= FPGA_CONFIG_BUFFER_SIZE; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 66 | } else { |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 67 | args[2] = bytes_per_block; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 68 | } |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 69 | |
| 70 | buffer->size_written += args[2]; |
Abdul Halim, Muhammad Hadi Asyrafi | 20a07f3 | 2020-05-18 11:16:48 +0800 | [diff] [blame] | 71 | mailbox_send_cmd_async(&send_id, MBOX_RECONFIG_DATA, args, |
Abdul Halim, Muhammad Hadi Asyrafi | 118ab21 | 2020-10-15 15:27:18 +0800 | [diff] [blame] | 72 | 3U, CMD_INDIRECT); |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 73 | |
| 74 | buffer->subblocks_sent++; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 75 | max_blocks--; |
| 76 | } |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 77 | |
| 78 | return !max_blocks; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static int intel_fpga_sdm_write_all(void) |
| 82 | { |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 83 | for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) { |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 84 | if (intel_fpga_sdm_write_buffer( |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 85 | &fpga_config_buffers[current_buffer])) { |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 86 | break; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 87 | } |
| 88 | } |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
Hadi Asyrafi | 0c6dae2 | 2019-12-17 23:33:39 +0800 | [diff] [blame] | 92 | static uint32_t intel_mailbox_fpga_config_isdone(uint32_t query_type) |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 93 | { |
Hadi Asyrafi | 0c6dae2 | 2019-12-17 23:33:39 +0800 | [diff] [blame] | 94 | uint32_t ret; |
| 95 | |
Kris Chaplin | e768dfa | 2021-06-25 11:31:52 +0100 | [diff] [blame] | 96 | if (query_type == 1U) { |
Sieu Mun Tang | 2468266 | 2022-02-19 21:49:48 +0800 | [diff] [blame] | 97 | ret = intel_mailbox_get_config_status(MBOX_CONFIG_STATUS, false); |
Kris Chaplin | e768dfa | 2021-06-25 11:31:52 +0100 | [diff] [blame] | 98 | } else { |
Sieu Mun Tang | 2468266 | 2022-02-19 21:49:48 +0800 | [diff] [blame] | 99 | ret = intel_mailbox_get_config_status(MBOX_RECONFIG_STATUS, true); |
Kris Chaplin | e768dfa | 2021-06-25 11:31:52 +0100 | [diff] [blame] | 100 | } |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 101 | |
Abdul Halim, Muhammad Hadi Asyrafi | 959143d | 2020-12-29 16:49:23 +0800 | [diff] [blame] | 102 | if (ret != 0U) { |
Kris Chaplin | e768dfa | 2021-06-25 11:31:52 +0100 | [diff] [blame] | 103 | if (ret == MBOX_CFGSTAT_STATE_CONFIG) { |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 104 | return INTEL_SIP_SMC_STATUS_BUSY; |
Kris Chaplin | e768dfa | 2021-06-25 11:31:52 +0100 | [diff] [blame] | 105 | } else { |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 106 | return INTEL_SIP_SMC_STATUS_ERROR; |
Kris Chaplin | e768dfa | 2021-06-25 11:31:52 +0100 | [diff] [blame] | 107 | } |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 108 | } |
| 109 | |
Sieu Mun Tang | 5406498 | 2022-04-28 22:40:58 +0800 | [diff] [blame] | 110 | if (bridge_disable) { |
Sieu Mun Tang | 82cf5df | 2022-05-05 17:07:21 +0800 | [diff] [blame] | 111 | socfpga_bridges_enable(~0); /* Enable bridge */ |
Sieu Mun Tang | 5406498 | 2022-04-28 22:40:58 +0800 | [diff] [blame] | 112 | bridge_disable = false; |
Hadi Asyrafi | 36a9f30 | 2019-12-24 10:42:52 +0800 | [diff] [blame] | 113 | } |
| 114 | |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 115 | return INTEL_SIP_SMC_STATUS_OK; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static int mark_last_buffer_xfer_completed(uint32_t *buffer_addr_completed) |
| 119 | { |
| 120 | int i; |
| 121 | |
| 122 | for (i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) { |
| 123 | if (fpga_config_buffers[i].block_number == current_block) { |
| 124 | fpga_config_buffers[i].subblocks_sent--; |
| 125 | if (fpga_config_buffers[i].subblocks_sent == 0 |
| 126 | && fpga_config_buffers[i].size <= |
| 127 | fpga_config_buffers[i].size_written) { |
| 128 | fpga_config_buffers[i].write_requested = 0; |
| 129 | current_block++; |
| 130 | *buffer_addr_completed = |
| 131 | fpga_config_buffers[i].addr; |
| 132 | return 0; |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | return -1; |
| 138 | } |
| 139 | |
Hadi Asyrafi | cee6aa9 | 2019-12-17 15:25:04 +0800 | [diff] [blame] | 140 | static int intel_fpga_config_completed_write(uint32_t *completed_addr, |
Abdul Halim, Muhammad Hadi Asyrafi | 20a07f3 | 2020-05-18 11:16:48 +0800 | [diff] [blame] | 141 | uint32_t *count, uint32_t *job_id) |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 142 | { |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 143 | uint32_t resp[5]; |
Sieu Mun Tang | 2468266 | 2022-02-19 21:49:48 +0800 | [diff] [blame] | 144 | unsigned int resp_len = ARRAY_SIZE(resp); |
| 145 | int status = INTEL_SIP_SMC_STATUS_OK; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 146 | int all_completed = 1; |
Sieu Mun Tang | 2468266 | 2022-02-19 21:49:48 +0800 | [diff] [blame] | 147 | *count = 0; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 148 | |
Tien Hock, Loh | 500b232 | 2019-10-30 14:49:40 +0800 | [diff] [blame] | 149 | while (*count < 3) { |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 150 | |
Sieu Mun Tang | 2468266 | 2022-02-19 21:49:48 +0800 | [diff] [blame] | 151 | status = mailbox_read_response(job_id, |
| 152 | resp, &resp_len); |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 153 | |
Sieu Mun Tang | 9f22cbf | 2022-03-02 11:04:09 +0800 | [diff] [blame] | 154 | if (status < 0) { |
Tien Hock, Loh | 500b232 | 2019-10-30 14:49:40 +0800 | [diff] [blame] | 155 | break; |
Sieu Mun Tang | 9f22cbf | 2022-03-02 11:04:09 +0800 | [diff] [blame] | 156 | } |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 157 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 158 | max_blocks++; |
Tien Hock, Loh | 500b232 | 2019-10-30 14:49:40 +0800 | [diff] [blame] | 159 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 160 | if (mark_last_buffer_xfer_completed( |
Sieu Mun Tang | 9f22cbf | 2022-03-02 11:04:09 +0800 | [diff] [blame] | 161 | &completed_addr[*count]) == 0) { |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 162 | *count = *count + 1; |
Sieu Mun Tang | 9f22cbf | 2022-03-02 11:04:09 +0800 | [diff] [blame] | 163 | } else { |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 164 | break; |
Sieu Mun Tang | 9f22cbf | 2022-03-02 11:04:09 +0800 | [diff] [blame] | 165 | } |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | if (*count <= 0) { |
Sieu Mun Tang | 9f22cbf | 2022-03-02 11:04:09 +0800 | [diff] [blame] | 169 | if (status != MBOX_NO_RESPONSE && |
| 170 | status != MBOX_TIMEOUT && resp_len != 0) { |
Tien Hock, Loh | 500b232 | 2019-10-30 14:49:40 +0800 | [diff] [blame] | 171 | mailbox_clear_response(); |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 172 | return INTEL_SIP_SMC_STATUS_ERROR; |
| 173 | } |
| 174 | |
| 175 | *count = 0; |
| 176 | } |
| 177 | |
| 178 | intel_fpga_sdm_write_all(); |
| 179 | |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 180 | if (*count > 0) { |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 181 | status = INTEL_SIP_SMC_STATUS_OK; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 182 | } else if (*count == 0) { |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 183 | status = INTEL_SIP_SMC_STATUS_BUSY; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 184 | } |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 185 | |
| 186 | for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) { |
| 187 | if (fpga_config_buffers[i].write_requested != 0) { |
| 188 | all_completed = 0; |
| 189 | break; |
| 190 | } |
| 191 | } |
| 192 | |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 193 | if (all_completed == 1) { |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 194 | return INTEL_SIP_SMC_STATUS_OK; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 195 | } |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 196 | |
| 197 | return status; |
| 198 | } |
| 199 | |
Sieu Mun Tang | 5406498 | 2022-04-28 22:40:58 +0800 | [diff] [blame] | 200 | static int intel_fpga_config_start(uint32_t flag) |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 201 | { |
Sieu Mun Tang | 2468266 | 2022-02-19 21:49:48 +0800 | [diff] [blame] | 202 | uint32_t argument = 0x1; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 203 | uint32_t response[3]; |
| 204 | int status = 0; |
Sieu Mun Tang | 2468266 | 2022-02-19 21:49:48 +0800 | [diff] [blame] | 205 | unsigned int size = 0; |
| 206 | unsigned int resp_len = ARRAY_SIZE(response); |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 207 | |
Sieu Mun Tang | 5406498 | 2022-04-28 22:40:58 +0800 | [diff] [blame] | 208 | if (!CONFIG_TEST_FLAG(flag, PARTIAL_CONFIG)) { |
| 209 | bridge_disable = true; |
Abdul Halim, Muhammad Hadi Asyrafi | b251c33 | 2020-05-29 12:13:17 +0800 | [diff] [blame] | 210 | } |
Hadi Asyrafi | 36a9f30 | 2019-12-24 10:42:52 +0800 | [diff] [blame] | 211 | |
Sieu Mun Tang | 5406498 | 2022-04-28 22:40:58 +0800 | [diff] [blame] | 212 | if (CONFIG_TEST_FLAG(flag, AUTHENTICATION)) { |
| 213 | size = 1; |
| 214 | bridge_disable = false; |
| 215 | } |
| 216 | |
Tien Hock, Loh | 500b232 | 2019-10-30 14:49:40 +0800 | [diff] [blame] | 217 | mailbox_clear_response(); |
| 218 | |
Sieu Mun Tang | 2468266 | 2022-02-19 21:49:48 +0800 | [diff] [blame] | 219 | mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_CANCEL, NULL, 0U, |
| 220 | CMD_CASUAL, NULL, NULL); |
Tien Hock, Loh | 500b232 | 2019-10-30 14:49:40 +0800 | [diff] [blame] | 221 | |
Sieu Mun Tang | 2468266 | 2022-02-19 21:49:48 +0800 | [diff] [blame] | 222 | status = mailbox_send_cmd(MBOX_JOB_ID, MBOX_RECONFIG, &argument, size, |
| 223 | CMD_CASUAL, response, &resp_len); |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 224 | |
Abdul Halim, Muhammad Hadi Asyrafi | fbc3913 | 2020-11-20 11:06:00 +0800 | [diff] [blame] | 225 | if (status < 0) { |
Sieu Mun Tang | 5406498 | 2022-04-28 22:40:58 +0800 | [diff] [blame] | 226 | bridge_disable = false; |
Abdul Halim, Muhammad Hadi Asyrafi | fbc3913 | 2020-11-20 11:06:00 +0800 | [diff] [blame] | 227 | return INTEL_SIP_SMC_STATUS_ERROR; |
| 228 | } |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 229 | |
| 230 | max_blocks = response[0]; |
| 231 | bytes_per_block = response[1]; |
| 232 | |
| 233 | for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) { |
| 234 | fpga_config_buffers[i].size = 0; |
| 235 | fpga_config_buffers[i].size_written = 0; |
| 236 | fpga_config_buffers[i].addr = 0; |
| 237 | fpga_config_buffers[i].write_requested = 0; |
| 238 | fpga_config_buffers[i].block_number = 0; |
| 239 | fpga_config_buffers[i].subblocks_sent = 0; |
| 240 | } |
| 241 | |
| 242 | blocks_submitted = 0; |
| 243 | current_block = 0; |
Tien Hock, Loh | 500b232 | 2019-10-30 14:49:40 +0800 | [diff] [blame] | 244 | read_block = 0; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 245 | current_buffer = 0; |
| 246 | |
Sieu Mun Tang | 5406498 | 2022-04-28 22:40:58 +0800 | [diff] [blame] | 247 | /* Disable bridge on full reconfiguration */ |
| 248 | if (bridge_disable) { |
Sieu Mun Tang | 82cf5df | 2022-05-05 17:07:21 +0800 | [diff] [blame] | 249 | socfpga_bridges_disable(~0); |
Hadi Asyrafi | 36a9f30 | 2019-12-24 10:42:52 +0800 | [diff] [blame] | 250 | } |
| 251 | |
Abdul Halim, Muhammad Hadi Asyrafi | fbc3913 | 2020-11-20 11:06:00 +0800 | [diff] [blame] | 252 | return INTEL_SIP_SMC_STATUS_OK; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 253 | } |
| 254 | |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 255 | static bool is_fpga_config_buffer_full(void) |
| 256 | { |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 257 | for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) { |
| 258 | if (!fpga_config_buffers[i].write_requested) { |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 259 | return false; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 260 | } |
| 261 | } |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 262 | return true; |
| 263 | } |
| 264 | |
Abdul Halim, Muhammad Hadi Asyrafi | 20a07f3 | 2020-05-18 11:16:48 +0800 | [diff] [blame] | 265 | bool is_address_in_ddr_range(uint64_t addr, uint64_t size) |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 266 | { |
Abdul Halim, Muhammad Hadi Asyrafi | 461f544 | 2020-07-03 13:22:09 +0800 | [diff] [blame] | 267 | if (!addr && !size) { |
| 268 | return true; |
| 269 | } |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 270 | if (size > (UINT64_MAX - addr)) { |
Abdul Halim, Muhammad Hadi Asyrafi | c39a0e0 | 2020-02-06 19:18:41 +0800 | [diff] [blame] | 271 | return false; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 272 | } |
| 273 | if (addr < BL31_LIMIT) { |
Abdul Halim, Muhammad Hadi Asyrafi | c39a0e0 | 2020-02-06 19:18:41 +0800 | [diff] [blame] | 274 | return false; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 275 | } |
| 276 | if (addr + size > DRAM_BASE + DRAM_SIZE) { |
Abdul Halim, Muhammad Hadi Asyrafi | c39a0e0 | 2020-02-06 19:18:41 +0800 | [diff] [blame] | 277 | return false; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 278 | } |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 279 | |
Abdul Halim, Muhammad Hadi Asyrafi | c39a0e0 | 2020-02-06 19:18:41 +0800 | [diff] [blame] | 280 | return true; |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 281 | } |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 282 | |
Hadi Asyrafi | cee6aa9 | 2019-12-17 15:25:04 +0800 | [diff] [blame] | 283 | static uint32_t intel_fpga_config_write(uint64_t mem, uint64_t size) |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 284 | { |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 285 | int i; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 286 | |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 287 | intel_fpga_sdm_write_all(); |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 288 | |
Abdul Halim, Muhammad Hadi Asyrafi | c39a0e0 | 2020-02-06 19:18:41 +0800 | [diff] [blame] | 289 | if (!is_address_in_ddr_range(mem, size) || |
Abdul Halim, Muhammad Hadi Asyrafi | 351e884 | 2020-11-05 18:00:03 +0800 | [diff] [blame] | 290 | is_fpga_config_buffer_full()) { |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 291 | return INTEL_SIP_SMC_STATUS_REJECTED; |
Abdul Halim, Muhammad Hadi Asyrafi | 351e884 | 2020-11-05 18:00:03 +0800 | [diff] [blame] | 292 | } |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 293 | |
| 294 | for (i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) { |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 295 | int j = (i + current_buffer) % FPGA_CONFIG_BUFFER_SIZE; |
| 296 | |
| 297 | if (!fpga_config_buffers[j].write_requested) { |
| 298 | fpga_config_buffers[j].addr = mem; |
| 299 | fpga_config_buffers[j].size = size; |
| 300 | fpga_config_buffers[j].size_written = 0; |
| 301 | fpga_config_buffers[j].write_requested = 1; |
| 302 | fpga_config_buffers[j].block_number = |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 303 | blocks_submitted++; |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 304 | fpga_config_buffers[j].subblocks_sent = 0; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 305 | break; |
| 306 | } |
| 307 | } |
| 308 | |
Abdul Halim, Muhammad Hadi Asyrafi | 351e884 | 2020-11-05 18:00:03 +0800 | [diff] [blame] | 309 | if (is_fpga_config_buffer_full()) { |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 310 | return INTEL_SIP_SMC_STATUS_BUSY; |
Abdul Halim, Muhammad Hadi Asyrafi | 351e884 | 2020-11-05 18:00:03 +0800 | [diff] [blame] | 311 | } |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 312 | |
Hadi Asyrafi | f3a7c14 | 2019-11-12 16:29:03 +0800 | [diff] [blame] | 313 | return INTEL_SIP_SMC_STATUS_OK; |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 314 | } |
| 315 | |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 316 | static int is_out_of_sec_range(uint64_t reg_addr) |
| 317 | { |
Siew Chin Lim | 869d4f5 | 2021-05-11 21:12:22 +0800 | [diff] [blame] | 318 | #if DEBUG |
| 319 | return 0; |
| 320 | #endif |
| 321 | |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 322 | switch (reg_addr) { |
| 323 | case(0xF8011100): /* ECCCTRL1 */ |
| 324 | case(0xF8011104): /* ECCCTRL2 */ |
| 325 | case(0xF8011110): /* ERRINTEN */ |
| 326 | case(0xF8011114): /* ERRINTENS */ |
| 327 | case(0xF8011118): /* ERRINTENR */ |
| 328 | case(0xF801111C): /* INTMODE */ |
| 329 | case(0xF8011120): /* INTSTAT */ |
| 330 | case(0xF8011124): /* DIAGINTTEST */ |
| 331 | case(0xF801112C): /* DERRADDRA */ |
| 332 | case(0xFFD12028): /* SDMMCGRP_CTRL */ |
| 333 | case(0xFFD12044): /* EMAC0 */ |
| 334 | case(0xFFD12048): /* EMAC1 */ |
| 335 | case(0xFFD1204C): /* EMAC2 */ |
| 336 | case(0xFFD12090): /* ECC_INT_MASK_VALUE */ |
| 337 | case(0xFFD12094): /* ECC_INT_MASK_SET */ |
| 338 | case(0xFFD12098): /* ECC_INT_MASK_CLEAR */ |
| 339 | case(0xFFD1209C): /* ECC_INTSTATUS_SERR */ |
| 340 | case(0xFFD120A0): /* ECC_INTSTATUS_DERR */ |
| 341 | case(0xFFD120C0): /* NOC_TIMEOUT */ |
| 342 | case(0xFFD120C4): /* NOC_IDLEREQ_SET */ |
| 343 | case(0xFFD120C8): /* NOC_IDLEREQ_CLR */ |
| 344 | case(0xFFD120D0): /* NOC_IDLEACK */ |
| 345 | case(0xFFD120D4): /* NOC_IDLESTATUS */ |
| 346 | case(0xFFD12200): /* BOOT_SCRATCH_COLD0 */ |
| 347 | case(0xFFD12204): /* BOOT_SCRATCH_COLD1 */ |
| 348 | case(0xFFD12220): /* BOOT_SCRATCH_COLD8 */ |
| 349 | case(0xFFD12224): /* BOOT_SCRATCH_COLD9 */ |
| 350 | return 0; |
| 351 | |
| 352 | default: |
| 353 | break; |
| 354 | } |
| 355 | |
| 356 | return -1; |
| 357 | } |
| 358 | |
| 359 | /* Secure register access */ |
| 360 | uint32_t intel_secure_reg_read(uint64_t reg_addr, uint32_t *retval) |
| 361 | { |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 362 | if (is_out_of_sec_range(reg_addr)) { |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 363 | return INTEL_SIP_SMC_STATUS_ERROR; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 364 | } |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 365 | |
| 366 | *retval = mmio_read_32(reg_addr); |
| 367 | |
| 368 | return INTEL_SIP_SMC_STATUS_OK; |
| 369 | } |
| 370 | |
| 371 | uint32_t intel_secure_reg_write(uint64_t reg_addr, uint32_t val, |
| 372 | uint32_t *retval) |
| 373 | { |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 374 | if (is_out_of_sec_range(reg_addr)) { |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 375 | return INTEL_SIP_SMC_STATUS_ERROR; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 376 | } |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 377 | |
| 378 | mmio_write_32(reg_addr, val); |
| 379 | |
| 380 | return intel_secure_reg_read(reg_addr, retval); |
| 381 | } |
| 382 | |
| 383 | uint32_t intel_secure_reg_update(uint64_t reg_addr, uint32_t mask, |
| 384 | uint32_t val, uint32_t *retval) |
| 385 | { |
| 386 | if (!intel_secure_reg_read(reg_addr, retval)) { |
| 387 | *retval &= ~mask; |
Siew Chin Lim | a076315 | 2021-07-10 00:55:35 +0800 | [diff] [blame] | 388 | *retval |= val & mask; |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 389 | return intel_secure_reg_write(reg_addr, *retval, retval); |
| 390 | } |
| 391 | |
| 392 | return INTEL_SIP_SMC_STATUS_ERROR; |
| 393 | } |
| 394 | |
Hadi Asyrafi | 593c4c5 | 2019-12-17 19:22:17 +0800 | [diff] [blame] | 395 | /* Intel Remote System Update (RSU) services */ |
| 396 | uint64_t intel_rsu_update_address; |
| 397 | |
Abdul Halim, Muhammad Hadi Asyrafi | 118ab21 | 2020-10-15 15:27:18 +0800 | [diff] [blame] | 398 | static uint32_t intel_rsu_status(uint64_t *respbuf, unsigned int respbuf_sz) |
Hadi Asyrafi | 593c4c5 | 2019-12-17 19:22:17 +0800 | [diff] [blame] | 399 | { |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 400 | if (mailbox_rsu_status((uint32_t *)respbuf, respbuf_sz) < 0) { |
Abdul Halim, Muhammad Hadi Asyrafi | 25f623e | 2020-02-27 10:23:48 +0800 | [diff] [blame] | 401 | return INTEL_SIP_SMC_RSU_ERROR; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 402 | } |
Hadi Asyrafi | 593c4c5 | 2019-12-17 19:22:17 +0800 | [diff] [blame] | 403 | |
| 404 | return INTEL_SIP_SMC_STATUS_OK; |
| 405 | } |
| 406 | |
| 407 | static uint32_t intel_rsu_update(uint64_t update_address) |
| 408 | { |
| 409 | intel_rsu_update_address = update_address; |
| 410 | return INTEL_SIP_SMC_STATUS_OK; |
| 411 | } |
| 412 | |
Abdul Halim, Muhammad Hadi Asyrafi | d84bfef | 2020-02-25 16:28:10 +0800 | [diff] [blame] | 413 | static uint32_t intel_rsu_notify(uint32_t execution_stage) |
Hadi Asyrafi | 593c4c5 | 2019-12-17 19:22:17 +0800 | [diff] [blame] | 414 | { |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 415 | if (mailbox_hps_stage_notify(execution_stage) < 0) { |
Abdul Halim, Muhammad Hadi Asyrafi | 25f623e | 2020-02-27 10:23:48 +0800 | [diff] [blame] | 416 | return INTEL_SIP_SMC_RSU_ERROR; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 417 | } |
Hadi Asyrafi | 593c4c5 | 2019-12-17 19:22:17 +0800 | [diff] [blame] | 418 | |
| 419 | return INTEL_SIP_SMC_STATUS_OK; |
| 420 | } |
| 421 | |
| 422 | static uint32_t intel_rsu_retry_counter(uint32_t *respbuf, uint32_t respbuf_sz, |
| 423 | uint32_t *ret_stat) |
| 424 | { |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 425 | if (mailbox_rsu_status((uint32_t *)respbuf, respbuf_sz) < 0) { |
Abdul Halim, Muhammad Hadi Asyrafi | 25f623e | 2020-02-27 10:23:48 +0800 | [diff] [blame] | 426 | return INTEL_SIP_SMC_RSU_ERROR; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 427 | } |
Hadi Asyrafi | 593c4c5 | 2019-12-17 19:22:17 +0800 | [diff] [blame] | 428 | |
| 429 | *ret_stat = respbuf[8]; |
| 430 | return INTEL_SIP_SMC_STATUS_OK; |
| 431 | } |
| 432 | |
Chee Hong Ang | 2cfd8ec | 2020-05-13 11:44:04 +0800 | [diff] [blame] | 433 | static uint32_t intel_rsu_copy_dcmf_version(uint64_t dcmf_ver_1_0, |
| 434 | uint64_t dcmf_ver_3_2) |
| 435 | { |
| 436 | rsu_dcmf_ver[0] = dcmf_ver_1_0; |
| 437 | rsu_dcmf_ver[1] = dcmf_ver_1_0 >> 32; |
| 438 | rsu_dcmf_ver[2] = dcmf_ver_3_2; |
| 439 | rsu_dcmf_ver[3] = dcmf_ver_3_2 >> 32; |
| 440 | |
| 441 | return INTEL_SIP_SMC_STATUS_OK; |
| 442 | } |
| 443 | |
Sieu Mun Tang | e6d5de9 | 2022-04-28 22:21:01 +0800 | [diff] [blame] | 444 | static uint32_t intel_rsu_copy_dcmf_status(uint64_t dcmf_stat) |
| 445 | { |
| 446 | rsu_dcmf_stat[0] = 0xFFFF & (dcmf_stat >> (0 * 16)); |
| 447 | rsu_dcmf_stat[1] = 0xFFFF & (dcmf_stat >> (1 * 16)); |
| 448 | rsu_dcmf_stat[2] = 0xFFFF & (dcmf_stat >> (2 * 16)); |
| 449 | rsu_dcmf_stat[3] = 0xFFFF & (dcmf_stat >> (3 * 16)); |
| 450 | |
| 451 | return INTEL_SIP_SMC_STATUS_OK; |
| 452 | } |
| 453 | |
Kris Chaplin | e768dfa | 2021-06-25 11:31:52 +0100 | [diff] [blame] | 454 | /* Intel HWMON services */ |
| 455 | static uint32_t intel_hwmon_readtemp(uint32_t chan, uint32_t *retval) |
| 456 | { |
| 457 | if (chan > TEMP_CHANNEL_MAX) { |
| 458 | return INTEL_SIP_SMC_STATUS_ERROR; |
| 459 | } |
| 460 | |
| 461 | if (mailbox_hwmon_readtemp(chan, retval) < 0) { |
| 462 | return INTEL_SIP_SMC_STATUS_ERROR; |
| 463 | } |
| 464 | |
| 465 | return INTEL_SIP_SMC_STATUS_OK; |
| 466 | } |
| 467 | |
| 468 | static uint32_t intel_hwmon_readvolt(uint32_t chan, uint32_t *retval) |
| 469 | { |
| 470 | if (chan > VOLT_CHANNEL_MAX) { |
| 471 | return INTEL_SIP_SMC_STATUS_ERROR; |
| 472 | } |
| 473 | |
| 474 | if (mailbox_hwmon_readvolt(chan, retval) < 0) { |
| 475 | return INTEL_SIP_SMC_STATUS_ERROR; |
| 476 | } |
| 477 | |
| 478 | return INTEL_SIP_SMC_STATUS_OK; |
| 479 | } |
| 480 | |
Hadi Asyrafi | a33e810 | 2019-12-17 19:30:41 +0800 | [diff] [blame] | 481 | /* Mailbox services */ |
Abdul Halim, Muhammad Hadi Asyrafi | d9006fc | 2021-02-05 11:50:58 +0800 | [diff] [blame] | 482 | static uint32_t intel_smc_fw_version(uint32_t *fw_version) |
| 483 | { |
Sieu Mun Tang | bfda95a | 2022-04-27 18:54:10 +0800 | [diff] [blame] | 484 | int status; |
| 485 | unsigned int resp_len = CONFIG_STATUS_WORD_SIZE; |
| 486 | uint32_t resp_data[CONFIG_STATUS_WORD_SIZE] = {0U}; |
| 487 | |
| 488 | status = mailbox_send_cmd(MBOX_JOB_ID, MBOX_CONFIG_STATUS, NULL, 0U, |
| 489 | CMD_CASUAL, resp_data, &resp_len); |
| 490 | |
| 491 | if (status < 0) { |
| 492 | return INTEL_SIP_SMC_STATUS_ERROR; |
| 493 | } |
| 494 | |
| 495 | if (resp_len <= CONFIG_STATUS_FW_VER_OFFSET) { |
| 496 | return INTEL_SIP_SMC_STATUS_ERROR; |
| 497 | } |
| 498 | |
| 499 | *fw_version = resp_data[CONFIG_STATUS_FW_VER_OFFSET] & CONFIG_STATUS_FW_VER_MASK; |
Abdul Halim, Muhammad Hadi Asyrafi | d9006fc | 2021-02-05 11:50:58 +0800 | [diff] [blame] | 500 | |
| 501 | return INTEL_SIP_SMC_STATUS_OK; |
| 502 | } |
| 503 | |
Sieu Mun Tang | 2468266 | 2022-02-19 21:49:48 +0800 | [diff] [blame] | 504 | static uint32_t intel_mbox_send_cmd(uint32_t cmd, uint32_t *args, |
| 505 | unsigned int len, |
| 506 | uint32_t urgent, uint32_t *response, |
| 507 | unsigned int resp_len, int *mbox_status, |
| 508 | unsigned int *len_in_resp) |
Hadi Asyrafi | a33e810 | 2019-12-17 19:30:41 +0800 | [diff] [blame] | 509 | { |
Abdul Halim, Muhammad Hadi Asyrafi | c39a0e0 | 2020-02-06 19:18:41 +0800 | [diff] [blame] | 510 | *len_in_resp = 0; |
Sieu Mun Tang | 96bbdca | 2022-04-12 15:00:13 +0800 | [diff] [blame] | 511 | *mbox_status = GENERIC_RESPONSE_ERROR; |
Abdul Halim, Muhammad Hadi Asyrafi | c39a0e0 | 2020-02-06 19:18:41 +0800 | [diff] [blame] | 512 | |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 513 | if (!is_address_in_ddr_range((uint64_t)args, sizeof(uint32_t) * len)) { |
Abdul Halim, Muhammad Hadi Asyrafi | c39a0e0 | 2020-02-06 19:18:41 +0800 | [diff] [blame] | 514 | return INTEL_SIP_SMC_STATUS_REJECTED; |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 515 | } |
Abdul Halim, Muhammad Hadi Asyrafi | c39a0e0 | 2020-02-06 19:18:41 +0800 | [diff] [blame] | 516 | |
Hadi Asyrafi | a33e810 | 2019-12-17 19:30:41 +0800 | [diff] [blame] | 517 | int status = mailbox_send_cmd(MBOX_JOB_ID, cmd, args, len, urgent, |
Sieu Mun Tang | 2468266 | 2022-02-19 21:49:48 +0800 | [diff] [blame] | 518 | response, &resp_len); |
Hadi Asyrafi | a33e810 | 2019-12-17 19:30:41 +0800 | [diff] [blame] | 519 | |
| 520 | if (status < 0) { |
Hadi Asyrafi | a33e810 | 2019-12-17 19:30:41 +0800 | [diff] [blame] | 521 | *mbox_status = -status; |
| 522 | return INTEL_SIP_SMC_STATUS_ERROR; |
| 523 | } |
| 524 | |
| 525 | *mbox_status = 0; |
Sieu Mun Tang | 2468266 | 2022-02-19 21:49:48 +0800 | [diff] [blame] | 526 | *len_in_resp = resp_len; |
Hadi Asyrafi | a33e810 | 2019-12-17 19:30:41 +0800 | [diff] [blame] | 527 | return INTEL_SIP_SMC_STATUS_OK; |
| 528 | } |
| 529 | |
Sieu Mun Tang | 2b8e005 | 2022-04-27 18:57:29 +0800 | [diff] [blame] | 530 | static int intel_smc_get_usercode(uint32_t *user_code) |
| 531 | { |
| 532 | int status; |
| 533 | unsigned int resp_len = sizeof(user_code) / MBOX_WORD_BYTE; |
| 534 | |
| 535 | status = mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_GET_USERCODE, NULL, |
| 536 | 0U, CMD_CASUAL, user_code, &resp_len); |
| 537 | |
| 538 | if (status < 0) { |
| 539 | return INTEL_SIP_SMC_STATUS_ERROR; |
| 540 | } |
| 541 | |
| 542 | return INTEL_SIP_SMC_STATUS_OK; |
| 543 | } |
| 544 | |
Sieu Mun Tang | fd8a8ad | 2022-05-07 00:50:37 +0800 | [diff] [blame] | 545 | uint32_t intel_smc_service_completed(uint64_t addr, uint32_t size, |
| 546 | uint32_t mode, uint32_t *job_id, |
| 547 | uint32_t *ret_size, uint32_t *mbox_error) |
| 548 | { |
| 549 | int status = 0; |
| 550 | uint32_t resp_len = size / MBOX_WORD_BYTE; |
| 551 | |
| 552 | if (resp_len > MBOX_DATA_MAX_LEN) { |
| 553 | return INTEL_SIP_SMC_STATUS_REJECTED; |
| 554 | } |
| 555 | |
| 556 | if (!is_address_in_ddr_range(addr, size)) { |
| 557 | return INTEL_SIP_SMC_STATUS_REJECTED; |
| 558 | } |
| 559 | |
| 560 | if (mode == SERVICE_COMPLETED_MODE_ASYNC) { |
| 561 | status = mailbox_read_response_async(job_id, |
| 562 | NULL, (uint32_t *) addr, &resp_len, 0); |
| 563 | } else { |
| 564 | status = mailbox_read_response(job_id, |
| 565 | (uint32_t *) addr, &resp_len); |
| 566 | |
| 567 | if (status == MBOX_NO_RESPONSE) { |
| 568 | status = MBOX_BUSY; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | if (status == MBOX_NO_RESPONSE) { |
| 573 | return INTEL_SIP_SMC_STATUS_NO_RESPONSE; |
| 574 | } |
| 575 | |
| 576 | if (status == MBOX_BUSY) { |
| 577 | return INTEL_SIP_SMC_STATUS_BUSY; |
| 578 | } |
| 579 | |
| 580 | *ret_size = resp_len * MBOX_WORD_BYTE; |
| 581 | flush_dcache_range(addr, *ret_size); |
| 582 | |
| 583 | if (status != MBOX_RET_OK) { |
| 584 | *mbox_error = -status; |
| 585 | return INTEL_SIP_SMC_STATUS_ERROR; |
| 586 | } |
| 587 | |
| 588 | return INTEL_SIP_SMC_STATUS_OK; |
| 589 | } |
| 590 | |
Sieu Mun Tang | 758a2ad | 2022-05-11 10:23:13 +0800 | [diff] [blame] | 591 | /* Miscellaneous HPS services */ |
| 592 | uint32_t intel_hps_set_bridges(uint64_t enable, uint64_t mask) |
| 593 | { |
| 594 | int status = 0; |
| 595 | |
| 596 | if (enable & SOCFPGA_BRIDGE_ENABLE) { |
| 597 | if ((enable & SOCFPGA_BRIDGE_HAS_MASK) != 0) { |
| 598 | status = socfpga_bridges_enable((uint32_t)mask); |
| 599 | } else { |
| 600 | status = socfpga_bridges_enable(~0); |
| 601 | } |
| 602 | } else { |
| 603 | if ((enable & SOCFPGA_BRIDGE_HAS_MASK) != 0) { |
| 604 | status = socfpga_bridges_disable((uint32_t)mask); |
| 605 | } else { |
| 606 | status = socfpga_bridges_disable(~0); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | if (status < 0) { |
| 611 | return INTEL_SIP_SMC_STATUS_ERROR; |
| 612 | } |
| 613 | |
| 614 | return INTEL_SIP_SMC_STATUS_OK; |
| 615 | } |
| 616 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 617 | /* |
| 618 | * This function is responsible for handling all SiP calls from the NS world |
| 619 | */ |
| 620 | |
| 621 | uintptr_t sip_smc_handler(uint32_t smc_fid, |
| 622 | u_register_t x1, |
| 623 | u_register_t x2, |
| 624 | u_register_t x3, |
| 625 | u_register_t x4, |
| 626 | void *cookie, |
| 627 | void *handle, |
| 628 | u_register_t flags) |
| 629 | { |
Sieu Mun Tang | 2a820b9 | 2022-05-11 09:59:55 +0800 | [diff] [blame] | 630 | uint32_t retval = 0, completed_addr[3]; |
| 631 | uint32_t retval2 = 0; |
Sieu Mun Tang | a34b881 | 2022-03-17 03:11:55 +0800 | [diff] [blame] | 632 | uint32_t mbox_error = 0; |
Sieu Mun Tang | a34b881 | 2022-03-17 03:11:55 +0800 | [diff] [blame] | 633 | uint64_t retval64, rsu_respbuf[9]; |
Sieu Mun Tang | 9f22cbf | 2022-03-02 11:04:09 +0800 | [diff] [blame] | 634 | int status = INTEL_SIP_SMC_STATUS_OK; |
Sieu Mun Tang | 2468266 | 2022-02-19 21:49:48 +0800 | [diff] [blame] | 635 | int mbox_status; |
| 636 | unsigned int len_in_resp; |
Sieu Mun Tang | 583149a | 2022-05-10 17:27:12 +0800 | [diff] [blame] | 637 | u_register_t x5, x6, x7; |
Abdul Halim, Muhammad Hadi Asyrafi | b45f15e | 2020-05-14 15:32:43 +0800 | [diff] [blame] | 638 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 639 | switch (smc_fid) { |
| 640 | case SIP_SVC_UID: |
| 641 | /* Return UID to the caller */ |
| 642 | SMC_UUID_RET(handle, intl_svc_uid); |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 643 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 644 | case INTEL_SIP_SMC_FPGA_CONFIG_ISDONE: |
Hadi Asyrafi | 0c6dae2 | 2019-12-17 23:33:39 +0800 | [diff] [blame] | 645 | status = intel_mailbox_fpga_config_isdone(x1); |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 646 | SMC_RET4(handle, status, 0, 0, 0); |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 647 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 648 | case INTEL_SIP_SMC_FPGA_CONFIG_GET_MEM: |
| 649 | SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK, |
| 650 | INTEL_SIP_SMC_FPGA_CONFIG_ADDR, |
| 651 | INTEL_SIP_SMC_FPGA_CONFIG_SIZE - |
| 652 | INTEL_SIP_SMC_FPGA_CONFIG_ADDR); |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 653 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 654 | case INTEL_SIP_SMC_FPGA_CONFIG_START: |
| 655 | status = intel_fpga_config_start(x1); |
| 656 | SMC_RET4(handle, status, 0, 0, 0); |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 657 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 658 | case INTEL_SIP_SMC_FPGA_CONFIG_WRITE: |
| 659 | status = intel_fpga_config_write(x1, x2); |
| 660 | SMC_RET4(handle, status, 0, 0, 0); |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 661 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 662 | case INTEL_SIP_SMC_FPGA_CONFIG_COMPLETED_WRITE: |
| 663 | status = intel_fpga_config_completed_write(completed_addr, |
Abdul Halim, Muhammad Hadi Asyrafi | 20a07f3 | 2020-05-18 11:16:48 +0800 | [diff] [blame] | 664 | &retval, &rcv_id); |
| 665 | switch (retval) { |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 666 | case 1: |
| 667 | SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK, |
| 668 | completed_addr[0], 0, 0); |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 669 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 670 | case 2: |
| 671 | SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK, |
| 672 | completed_addr[0], |
| 673 | completed_addr[1], 0); |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 674 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 675 | case 3: |
| 676 | SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK, |
| 677 | completed_addr[0], |
| 678 | completed_addr[1], |
| 679 | completed_addr[2]); |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 680 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 681 | case 0: |
| 682 | SMC_RET4(handle, status, 0, 0, 0); |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 683 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 684 | default: |
Tien Hock, Loh | 500b232 | 2019-10-30 14:49:40 +0800 | [diff] [blame] | 685 | mailbox_clear_response(); |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 686 | SMC_RET1(handle, INTEL_SIP_SMC_STATUS_ERROR); |
| 687 | } |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 688 | |
| 689 | case INTEL_SIP_SMC_REG_READ: |
Abdul Halim, Muhammad Hadi Asyrafi | 20a07f3 | 2020-05-18 11:16:48 +0800 | [diff] [blame] | 690 | status = intel_secure_reg_read(x1, &retval); |
| 691 | SMC_RET3(handle, status, retval, x1); |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 692 | |
| 693 | case INTEL_SIP_SMC_REG_WRITE: |
Abdul Halim, Muhammad Hadi Asyrafi | 20a07f3 | 2020-05-18 11:16:48 +0800 | [diff] [blame] | 694 | status = intel_secure_reg_write(x1, (uint32_t)x2, &retval); |
| 695 | SMC_RET3(handle, status, retval, x1); |
Hadi Asyrafi | 6794230 | 2019-10-22 13:28:51 +0800 | [diff] [blame] | 696 | |
| 697 | case INTEL_SIP_SMC_REG_UPDATE: |
| 698 | status = intel_secure_reg_update(x1, (uint32_t)x2, |
Abdul Halim, Muhammad Hadi Asyrafi | 20a07f3 | 2020-05-18 11:16:48 +0800 | [diff] [blame] | 699 | (uint32_t)x3, &retval); |
| 700 | SMC_RET3(handle, status, retval, x1); |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 701 | |
Hadi Asyrafi | 593c4c5 | 2019-12-17 19:22:17 +0800 | [diff] [blame] | 702 | case INTEL_SIP_SMC_RSU_STATUS: |
| 703 | status = intel_rsu_status(rsu_respbuf, |
| 704 | ARRAY_SIZE(rsu_respbuf)); |
| 705 | if (status) { |
| 706 | SMC_RET1(handle, status); |
| 707 | } else { |
| 708 | SMC_RET4(handle, rsu_respbuf[0], rsu_respbuf[1], |
| 709 | rsu_respbuf[2], rsu_respbuf[3]); |
| 710 | } |
| 711 | |
| 712 | case INTEL_SIP_SMC_RSU_UPDATE: |
| 713 | status = intel_rsu_update(x1); |
| 714 | SMC_RET1(handle, status); |
| 715 | |
| 716 | case INTEL_SIP_SMC_RSU_NOTIFY: |
| 717 | status = intel_rsu_notify(x1); |
| 718 | SMC_RET1(handle, status); |
| 719 | |
| 720 | case INTEL_SIP_SMC_RSU_RETRY_COUNTER: |
| 721 | status = intel_rsu_retry_counter((uint32_t *)rsu_respbuf, |
Abdul Halim, Muhammad Hadi Asyrafi | 20a07f3 | 2020-05-18 11:16:48 +0800 | [diff] [blame] | 722 | ARRAY_SIZE(rsu_respbuf), &retval); |
Hadi Asyrafi | 593c4c5 | 2019-12-17 19:22:17 +0800 | [diff] [blame] | 723 | if (status) { |
| 724 | SMC_RET1(handle, status); |
| 725 | } else { |
Abdul Halim, Muhammad Hadi Asyrafi | 20a07f3 | 2020-05-18 11:16:48 +0800 | [diff] [blame] | 726 | SMC_RET2(handle, status, retval); |
Hadi Asyrafi | 593c4c5 | 2019-12-17 19:22:17 +0800 | [diff] [blame] | 727 | } |
| 728 | |
Chee Hong Ang | 2cfd8ec | 2020-05-13 11:44:04 +0800 | [diff] [blame] | 729 | case INTEL_SIP_SMC_RSU_DCMF_VERSION: |
| 730 | SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK, |
| 731 | ((uint64_t)rsu_dcmf_ver[1] << 32) | rsu_dcmf_ver[0], |
| 732 | ((uint64_t)rsu_dcmf_ver[3] << 32) | rsu_dcmf_ver[2]); |
| 733 | |
| 734 | case INTEL_SIP_SMC_RSU_COPY_DCMF_VERSION: |
| 735 | status = intel_rsu_copy_dcmf_version(x1, x2); |
| 736 | SMC_RET1(handle, status); |
| 737 | |
Sieu Mun Tang | e6d5de9 | 2022-04-28 22:21:01 +0800 | [diff] [blame] | 738 | case INTEL_SIP_SMC_RSU_DCMF_STATUS: |
| 739 | SMC_RET2(handle, INTEL_SIP_SMC_STATUS_OK, |
| 740 | ((uint64_t)rsu_dcmf_stat[3] << 48) | |
| 741 | ((uint64_t)rsu_dcmf_stat[2] << 32) | |
| 742 | ((uint64_t)rsu_dcmf_stat[1] << 16) | |
| 743 | rsu_dcmf_stat[0]); |
| 744 | |
| 745 | case INTEL_SIP_SMC_RSU_COPY_DCMF_STATUS: |
| 746 | status = intel_rsu_copy_dcmf_status(x1); |
| 747 | SMC_RET1(handle, status); |
| 748 | |
Chee Hong Ang | 681631b | 2020-07-01 14:22:25 +0800 | [diff] [blame] | 749 | case INTEL_SIP_SMC_RSU_MAX_RETRY: |
| 750 | SMC_RET2(handle, INTEL_SIP_SMC_STATUS_OK, rsu_max_retry); |
| 751 | |
| 752 | case INTEL_SIP_SMC_RSU_COPY_MAX_RETRY: |
| 753 | rsu_max_retry = x1; |
| 754 | SMC_RET1(handle, INTEL_SIP_SMC_STATUS_OK); |
| 755 | |
Sieu Mun Tang | dbcc2cf | 2022-03-07 12:13:04 +0800 | [diff] [blame] | 756 | case INTEL_SIP_SMC_ECC_DBE: |
| 757 | status = intel_ecc_dbe_notification(x1); |
| 758 | SMC_RET1(handle, status); |
| 759 | |
Sieu Mun Tang | 758a2ad | 2022-05-11 10:23:13 +0800 | [diff] [blame] | 760 | case INTEL_SIP_SMC_SERVICE_COMPLETED: |
| 761 | status = intel_smc_service_completed(x1, x2, x3, &rcv_id, |
| 762 | &len_in_resp, &mbox_error); |
| 763 | SMC_RET4(handle, status, mbox_error, x1, len_in_resp); |
| 764 | |
Abdul Halim, Muhammad Hadi Asyrafi | d9006fc | 2021-02-05 11:50:58 +0800 | [diff] [blame] | 765 | case INTEL_SIP_SMC_FIRMWARE_VERSION: |
| 766 | status = intel_smc_fw_version(&retval); |
Sieu Mun Tang | bfda95a | 2022-04-27 18:54:10 +0800 | [diff] [blame] | 767 | SMC_RET2(handle, status, retval); |
Abdul Halim, Muhammad Hadi Asyrafi | d9006fc | 2021-02-05 11:50:58 +0800 | [diff] [blame] | 768 | |
Hadi Asyrafi | a33e810 | 2019-12-17 19:30:41 +0800 | [diff] [blame] | 769 | case INTEL_SIP_SMC_MBOX_SEND_CMD: |
| 770 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 771 | x6 = SMC_GET_GP(handle, CTX_GPREG_X6); |
Abdul Halim, Muhammad Hadi Asyrafi | d84bfef | 2020-02-25 16:28:10 +0800 | [diff] [blame] | 772 | status = intel_mbox_send_cmd(x1, (uint32_t *)x2, x3, x4, |
Hadi Asyrafi | a33e810 | 2019-12-17 19:30:41 +0800 | [diff] [blame] | 773 | (uint32_t *)x5, x6, &mbox_status, |
| 774 | &len_in_resp); |
Sieu Mun Tang | f02f0cb | 2022-02-19 20:36:41 +0800 | [diff] [blame] | 775 | SMC_RET3(handle, status, mbox_status, len_in_resp); |
Hadi Asyrafi | a33e810 | 2019-12-17 19:30:41 +0800 | [diff] [blame] | 776 | |
Sieu Mun Tang | 2b8e005 | 2022-04-27 18:57:29 +0800 | [diff] [blame] | 777 | case INTEL_SIP_SMC_GET_USERCODE: |
| 778 | status = intel_smc_get_usercode(&retval); |
| 779 | SMC_RET2(handle, status, retval); |
| 780 | |
Sieu Mun Tang | 128d2a7 | 2022-05-11 09:49:25 +0800 | [diff] [blame] | 781 | case INTEL_SIP_SMC_FCS_CRYPTION: |
| 782 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 783 | |
| 784 | if (x1 == FCS_MODE_DECRYPT) { |
| 785 | status = intel_fcs_decryption(x2, x3, x4, x5, &send_id); |
| 786 | } else if (x1 == FCS_MODE_ENCRYPT) { |
| 787 | status = intel_fcs_encryption(x2, x3, x4, x5, &send_id); |
| 788 | } else { |
| 789 | status = INTEL_SIP_SMC_STATUS_REJECTED; |
| 790 | } |
| 791 | |
| 792 | SMC_RET3(handle, status, x4, x5); |
| 793 | |
Sieu Mun Tang | 22322fb | 2022-05-09 16:05:58 +0800 | [diff] [blame] | 794 | case INTEL_SIP_SMC_FCS_CRYPTION_EXT: |
| 795 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 796 | x6 = SMC_GET_GP(handle, CTX_GPREG_X6); |
| 797 | x7 = SMC_GET_GP(handle, CTX_GPREG_X7); |
| 798 | |
| 799 | if (x3 == FCS_MODE_DECRYPT) { |
| 800 | status = intel_fcs_decryption_ext(x1, x2, x4, x5, x6, |
| 801 | (uint32_t *) &x7, &mbox_error); |
| 802 | } else if (x3 == FCS_MODE_ENCRYPT) { |
| 803 | status = intel_fcs_encryption_ext(x1, x2, x4, x5, x6, |
| 804 | (uint32_t *) &x7, &mbox_error); |
| 805 | } else { |
| 806 | status = INTEL_SIP_SMC_STATUS_REJECTED; |
| 807 | } |
| 808 | |
| 809 | SMC_RET4(handle, status, mbox_error, x6, x7); |
| 810 | |
Sieu Mun Tang | fd8a8ad | 2022-05-07 00:50:37 +0800 | [diff] [blame] | 811 | case INTEL_SIP_SMC_FCS_RANDOM_NUMBER: |
| 812 | status = intel_fcs_random_number_gen(x1, &retval64, |
| 813 | &mbox_error); |
| 814 | SMC_RET4(handle, status, mbox_error, x1, retval64); |
| 815 | |
Sieu Mun Tang | e7a037f | 2022-05-10 17:18:19 +0800 | [diff] [blame] | 816 | case INTEL_SIP_SMC_FCS_RANDOM_NUMBER_EXT: |
| 817 | status = intel_fcs_random_number_gen_ext(x1, x2, x3, |
| 818 | &send_id); |
| 819 | SMC_RET1(handle, status); |
| 820 | |
Sieu Mun Tang | fd8a8ad | 2022-05-07 00:50:37 +0800 | [diff] [blame] | 821 | case INTEL_SIP_SMC_FCS_SEND_CERTIFICATE: |
| 822 | status = intel_fcs_send_cert(x1, x2, &send_id); |
| 823 | SMC_RET1(handle, status); |
| 824 | |
| 825 | case INTEL_SIP_SMC_FCS_GET_PROVISION_DATA: |
| 826 | status = intel_fcs_get_provision_data(&send_id); |
| 827 | SMC_RET1(handle, status); |
| 828 | |
Sieu Mun Tang | a068fdf | 2022-05-11 10:01:54 +0800 | [diff] [blame] | 829 | case INTEL_SIP_SMC_FCS_CNTR_SET_PREAUTH: |
| 830 | status = intel_fcs_cntr_set_preauth(x1, x2, x3, |
| 831 | &mbox_error); |
| 832 | SMC_RET2(handle, status, mbox_error); |
| 833 | |
Sieu Mun Tang | 82cf5df | 2022-05-05 17:07:21 +0800 | [diff] [blame] | 834 | case INTEL_SIP_SMC_HPS_SET_BRIDGES: |
| 835 | status = intel_hps_set_bridges(x1, x2); |
| 836 | SMC_RET1(handle, status); |
| 837 | |
Sieu Mun Tang | 2a820b9 | 2022-05-11 09:59:55 +0800 | [diff] [blame] | 838 | case INTEL_SIP_SMC_FCS_PSGSIGMA_TEARDOWN: |
| 839 | status = intel_fcs_sigma_teardown(x1, &mbox_error); |
| 840 | SMC_RET2(handle, status, mbox_error); |
| 841 | |
| 842 | case INTEL_SIP_SMC_FCS_CHIP_ID: |
| 843 | status = intel_fcs_chip_id(&retval, &retval2, &mbox_error); |
| 844 | SMC_RET4(handle, status, mbox_error, retval, retval2); |
| 845 | |
| 846 | case INTEL_SIP_SMC_FCS_ATTESTATION_SUBKEY: |
| 847 | status = intel_fcs_attestation_subkey(x1, x2, x3, |
| 848 | (uint32_t *) &x4, &mbox_error); |
| 849 | SMC_RET4(handle, status, mbox_error, x3, x4); |
| 850 | |
| 851 | case INTEL_SIP_SMC_FCS_ATTESTATION_MEASUREMENTS: |
| 852 | status = intel_fcs_get_measurement(x1, x2, x3, |
| 853 | (uint32_t *) &x4, &mbox_error); |
| 854 | SMC_RET4(handle, status, mbox_error, x3, x4); |
| 855 | |
Sieu Mun Tang | 28af165 | 2022-05-09 10:48:53 +0800 | [diff] [blame] | 856 | case INTEL_SIP_SMC_FCS_GET_ATTESTATION_CERT: |
| 857 | status = intel_fcs_get_attestation_cert(x1, x2, |
| 858 | (uint32_t *) &x3, &mbox_error); |
| 859 | SMC_RET4(handle, status, mbox_error, x2, x3); |
| 860 | |
| 861 | case INTEL_SIP_SMC_FCS_CREATE_CERT_ON_RELOAD: |
| 862 | status = intel_fcs_create_cert_on_reload(x1, &mbox_error); |
| 863 | SMC_RET2(handle, status, mbox_error); |
| 864 | |
Sieu Mun Tang | 16754e1 | 2022-05-09 12:08:42 +0800 | [diff] [blame] | 865 | case INTEL_SIP_SMC_FCS_OPEN_CS_SESSION: |
| 866 | status = intel_fcs_open_crypto_service_session(&retval, &mbox_error); |
| 867 | SMC_RET3(handle, status, mbox_error, retval); |
| 868 | |
| 869 | case INTEL_SIP_SMC_FCS_CLOSE_CS_SESSION: |
| 870 | status = intel_fcs_close_crypto_service_session(x1, &mbox_error); |
| 871 | SMC_RET2(handle, status, mbox_error); |
| 872 | |
Sieu Mun Tang | fb1f6e9 | 2022-05-09 14:16:14 +0800 | [diff] [blame] | 873 | case INTEL_SIP_SMC_FCS_IMPORT_CS_KEY: |
| 874 | status = intel_fcs_import_crypto_service_key(x1, x2, &send_id); |
| 875 | SMC_RET1(handle, status); |
| 876 | |
| 877 | case INTEL_SIP_SMC_FCS_EXPORT_CS_KEY: |
| 878 | status = intel_fcs_export_crypto_service_key(x1, x2, x3, |
| 879 | (uint32_t *) &x4, &mbox_error); |
| 880 | SMC_RET4(handle, status, mbox_error, x3, x4); |
| 881 | |
| 882 | case INTEL_SIP_SMC_FCS_REMOVE_CS_KEY: |
| 883 | status = intel_fcs_remove_crypto_service_key(x1, x2, |
| 884 | &mbox_error); |
| 885 | SMC_RET2(handle, status, mbox_error); |
| 886 | |
| 887 | case INTEL_SIP_SMC_FCS_GET_CS_KEY_INFO: |
| 888 | status = intel_fcs_get_crypto_service_key_info(x1, x2, x3, |
| 889 | (uint32_t *) &x4, &mbox_error); |
| 890 | SMC_RET4(handle, status, mbox_error, x3, x4); |
| 891 | |
Sieu Mun Tang | d907cc3 | 2022-05-10 17:24:05 +0800 | [diff] [blame] | 892 | case INTEL_SIP_SMC_FCS_GET_DIGEST_INIT: |
| 893 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 894 | status = intel_fcs_get_digest_init(x1, x2, x3, |
| 895 | x4, x5, &mbox_error); |
| 896 | SMC_RET2(handle, status, mbox_error); |
| 897 | |
| 898 | case INTEL_SIP_SMC_FCS_GET_DIGEST_FINALIZE: |
| 899 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 900 | x6 = SMC_GET_GP(handle, CTX_GPREG_X6); |
| 901 | status = intel_fcs_get_digest_finalize(x1, x2, x3, |
| 902 | x4, x5, (uint32_t *) &x6, &mbox_error); |
| 903 | SMC_RET4(handle, status, mbox_error, x5, x6); |
| 904 | |
Sieu Mun Tang | 583149a | 2022-05-10 17:27:12 +0800 | [diff] [blame] | 905 | case INTEL_SIP_SMC_FCS_MAC_VERIFY_INIT: |
| 906 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 907 | status = intel_fcs_mac_verify_init(x1, x2, x3, |
| 908 | x4, x5, &mbox_error); |
| 909 | SMC_RET2(handle, status, mbox_error); |
| 910 | |
| 911 | case INTEL_SIP_SMC_FCS_MAC_VERIFY_FINALIZE: |
| 912 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 913 | x6 = SMC_GET_GP(handle, CTX_GPREG_X6); |
| 914 | x7 = SMC_GET_GP(handle, CTX_GPREG_X7); |
| 915 | status = intel_fcs_mac_verify_finalize(x1, x2, x3, |
| 916 | x4, x5, (uint32_t *) &x6, x7, &mbox_error); |
| 917 | SMC_RET4(handle, status, mbox_error, x5, x6); |
| 918 | |
Sieu Mun Tang | 153ecfb | 2022-05-10 17:39:26 +0800 | [diff] [blame] | 919 | case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIGN_INIT: |
| 920 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 921 | status = intel_fcs_ecdsa_sha2_data_sign_init(x1, x2, x3, |
| 922 | x4, x5, &mbox_error); |
| 923 | SMC_RET2(handle, status, mbox_error); |
| 924 | |
| 925 | case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIGN_FINALIZE: |
| 926 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 927 | x6 = SMC_GET_GP(handle, CTX_GPREG_X6); |
| 928 | status = intel_fcs_ecdsa_sha2_data_sign_finalize(x1, x2, x3, |
| 929 | x4, x5, (uint32_t *) &x6, &mbox_error); |
| 930 | SMC_RET4(handle, status, mbox_error, x5, x6); |
| 931 | |
Sieu Mun Tang | 8aa05ad | 2022-05-10 17:50:30 +0800 | [diff] [blame] | 932 | case INTEL_SIP_SMC_FCS_ECDSA_HASH_SIGN_INIT: |
| 933 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 934 | status = intel_fcs_ecdsa_hash_sign_init(x1, x2, x3, |
| 935 | x4, x5, &mbox_error); |
| 936 | SMC_RET2(handle, status, mbox_error); |
| 937 | |
| 938 | case INTEL_SIP_SMC_FCS_ECDSA_HASH_SIGN_FINALIZE: |
| 939 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 940 | x6 = SMC_GET_GP(handle, CTX_GPREG_X6); |
| 941 | status = intel_fcs_ecdsa_hash_sign_finalize(x1, x2, x3, |
| 942 | x4, x5, (uint32_t *) &x6, &mbox_error); |
| 943 | SMC_RET4(handle, status, mbox_error, x5, x6); |
| 944 | |
Sieu Mun Tang | 59357e8 | 2022-05-10 17:53:32 +0800 | [diff] [blame] | 945 | case INTEL_SIP_SMC_FCS_ECDSA_HASH_SIG_VERIFY_INIT: |
| 946 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 947 | status = intel_fcs_ecdsa_hash_sig_verify_init(x1, x2, x3, |
| 948 | x4, x5, &mbox_error); |
| 949 | SMC_RET2(handle, status, mbox_error); |
| 950 | |
| 951 | case INTEL_SIP_SMC_FCS_ECDSA_HASH_SIG_VERIFY_FINALIZE: |
| 952 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 953 | x6 = SMC_GET_GP(handle, CTX_GPREG_X6); |
| 954 | status = intel_fcs_ecdsa_hash_sig_verify_finalize(x1, x2, x3, |
| 955 | x4, x5, (uint32_t *) &x6, &mbox_error); |
| 956 | SMC_RET4(handle, status, mbox_error, x5, x6); |
| 957 | |
Sieu Mun Tang | dcaab77 | 2022-05-11 10:16:40 +0800 | [diff] [blame] | 958 | case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIG_VERIFY_INIT: |
| 959 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 960 | status = intel_fcs_ecdsa_sha2_data_sig_verify_init(x1, x2, x3, |
| 961 | x4, x5, &mbox_error); |
| 962 | SMC_RET2(handle, status, mbox_error); |
| 963 | |
| 964 | case INTEL_SIP_SMC_FCS_ECDSA_SHA2_DATA_SIG_VERIFY_FINALIZE: |
| 965 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 966 | x6 = SMC_GET_GP(handle, CTX_GPREG_X6); |
| 967 | x7 = SMC_GET_GP(handle, CTX_GPREG_X7); |
| 968 | status = intel_fcs_ecdsa_sha2_data_sig_verify_finalize(x1, x2, x3, |
| 969 | x4, x5, (uint32_t *) &x6, x7, &mbox_error); |
| 970 | SMC_RET4(handle, status, mbox_error, x5, x6); |
Sieu Mun Tang | 153ecfb | 2022-05-10 17:39:26 +0800 | [diff] [blame] | 971 | |
Sieu Mun Tang | e2f3ede | 2022-05-10 17:36:32 +0800 | [diff] [blame] | 972 | case INTEL_SIP_SMC_FCS_ECDSA_GET_PUBKEY_INIT: |
| 973 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 974 | status = intel_fcs_ecdsa_get_pubkey_init(x1, x2, x3, |
| 975 | x4, x5, &mbox_error); |
| 976 | SMC_RET2(handle, status, mbox_error); |
| 977 | |
| 978 | case INTEL_SIP_SMC_FCS_ECDSA_GET_PUBKEY_FINALIZE: |
| 979 | status = intel_fcs_ecdsa_get_pubkey_finalize(x1, x2, x3, |
| 980 | (uint32_t *) &x4, &mbox_error); |
| 981 | SMC_RET4(handle, status, mbox_error, x3, x4); |
| 982 | |
Sieu Mun Tang | 0675c22 | 2022-05-10 17:48:11 +0800 | [diff] [blame] | 983 | case INTEL_SIP_SMC_FCS_ECDH_REQUEST_INIT: |
| 984 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 985 | status = intel_fcs_ecdh_request_init(x1, x2, x3, |
| 986 | x4, x5, &mbox_error); |
| 987 | SMC_RET2(handle, status, mbox_error); |
| 988 | |
| 989 | case INTEL_SIP_SMC_FCS_ECDH_REQUEST_FINALIZE: |
| 990 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 991 | x6 = SMC_GET_GP(handle, CTX_GPREG_X6); |
| 992 | status = intel_fcs_ecdh_request_finalize(x1, x2, x3, |
| 993 | x4, x5, (uint32_t *) &x6, &mbox_error); |
| 994 | SMC_RET4(handle, status, mbox_error, x5, x6); |
| 995 | |
Sieu Mun Tang | b0c1d11 | 2022-05-10 17:30:00 +0800 | [diff] [blame] | 996 | case INTEL_SIP_SMC_FCS_AES_CRYPT_INIT: |
| 997 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 998 | status = intel_fcs_aes_crypt_init(x1, x2, x3, x4, x5, |
| 999 | &mbox_error); |
| 1000 | SMC_RET2(handle, status, mbox_error); |
| 1001 | |
| 1002 | case INTEL_SIP_SMC_FCS_AES_CRYPT_FINALIZE: |
| 1003 | x5 = SMC_GET_GP(handle, CTX_GPREG_X5); |
| 1004 | x6 = SMC_GET_GP(handle, CTX_GPREG_X6); |
| 1005 | status = intel_fcs_aes_crypt_finalize(x1, x2, x3, x4, x5, x6, |
| 1006 | &send_id); |
| 1007 | SMC_RET1(handle, status); |
| 1008 | |
Sieu Mun Tang | a34b881 | 2022-03-17 03:11:55 +0800 | [diff] [blame] | 1009 | case INTEL_SIP_SMC_GET_ROM_PATCH_SHA384: |
| 1010 | status = intel_fcs_get_rom_patch_sha384(x1, &retval64, |
| 1011 | &mbox_error); |
| 1012 | SMC_RET4(handle, status, mbox_error, x1, retval64); |
| 1013 | |
Sieu Mun Tang | f9cb657 | 2022-04-27 18:24:06 +0800 | [diff] [blame] | 1014 | case INTEL_SIP_SMC_SVC_VERSION: |
| 1015 | SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK, |
| 1016 | SIP_SVC_VERSION_MAJOR, |
| 1017 | SIP_SVC_VERSION_MINOR); |
| 1018 | |
Kris Chaplin | e768dfa | 2021-06-25 11:31:52 +0100 | [diff] [blame] | 1019 | case INTEL_SIP_SMC_HWMON_READTEMP: |
| 1020 | status = intel_hwmon_readtemp(x1, &retval); |
| 1021 | SMC_RET2(handle, status, retval); |
| 1022 | |
| 1023 | case INTEL_SIP_SMC_HWMON_READVOLT: |
| 1024 | status = intel_hwmon_readvolt(x1, &retval); |
| 1025 | SMC_RET2(handle, status, retval); |
| 1026 | |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 1027 | default: |
| 1028 | return socfpga_sip_handler(smc_fid, x1, x2, x3, x4, |
| 1029 | cookie, handle, flags); |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | DECLARE_RT_SVC( |
Hadi Asyrafi | 4d9f395 | 2019-10-23 17:35:32 +0800 | [diff] [blame] | 1034 | socfpga_sip_svc, |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 1035 | OEN_SIP_START, |
| 1036 | OEN_SIP_END, |
| 1037 | SMC_TYPE_FAST, |
| 1038 | NULL, |
| 1039 | sip_smc_handler |
| 1040 | ); |
| 1041 | |
| 1042 | DECLARE_RT_SVC( |
Hadi Asyrafi | 4d9f395 | 2019-10-23 17:35:32 +0800 | [diff] [blame] | 1043 | socfpga_sip_svc_std, |
Hadi Asyrafi | 616da77 | 2019-06-27 11:34:03 +0800 | [diff] [blame] | 1044 | OEN_SIP_START, |
| 1045 | OEN_SIP_END, |
| 1046 | SMC_TYPE_YIELD, |
| 1047 | NULL, |
| 1048 | sip_smc_handler |
| 1049 | ); |