Martin Roth | f95a11e | 2022-10-21 16:43:08 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | /* TODO: Update for Glinda */ |
| 4 | |
| 5 | #include "svc.h" |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <bl_uapp/bl_syscall_public.h> |
| 9 | #include <psp_verstage.h> |
Martin Roth | f95a11e | 2022-10-21 16:43:08 -0600 | [diff] [blame] | 10 | #include <string.h> |
| 11 | #include <svc_call.h> |
| 12 | |
| 13 | void svc_exit(uint32_t status) |
| 14 | { |
| 15 | uint32_t unused = 0; |
| 16 | SVC_CALL0(SVC_EXIT, unused); |
| 17 | } |
| 18 | |
| 19 | void svc_debug_print(const char *string) |
| 20 | { |
| 21 | uint32_t unused = 0; |
| 22 | struct cmd_param_debug param = { |
| 23 | .debug_buffer = (char *)string, |
| 24 | .debug_buffer_len = strlen(string), |
| 25 | }; |
| 26 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_DEBUG_PRINT, (void *)¶m, unused); |
| 27 | } |
| 28 | |
| 29 | void svc_debug_print_ex(uint32_t dword0, |
| 30 | uint32_t dword1, uint32_t dword2, uint32_t dword3) |
| 31 | { |
| 32 | uint32_t unused = 0; |
| 33 | struct cmd_param_debug_ex param = { |
| 34 | .word0 = dword0, |
| 35 | .word1 = dword1, |
| 36 | .word2 = dword2, |
| 37 | .word3 = dword3, |
| 38 | }; |
| 39 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_DEBUG_PRINT_EX, (void *)¶m, unused); |
| 40 | } |
| 41 | |
| 42 | uint32_t svc_get_boot_mode(uint32_t *boot_mode) |
| 43 | { |
| 44 | uint32_t retval = 0; |
| 45 | struct cmd_param_get_boot_mode param = { |
| 46 | .ptr_boot_mode = boot_mode, |
| 47 | }; |
| 48 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_GET_BOOT_MODE, (void *)¶m, retval); |
| 49 | return retval; |
| 50 | } |
| 51 | |
| 52 | void svc_delay_in_usec(uint32_t delay) |
| 53 | { |
| 54 | uint32_t unused = 0; |
| 55 | struct cmd_param_delay_in_micro_second param = { |
| 56 | .delay = delay, |
| 57 | }; |
| 58 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_DELAY_IN_MICRO_SECONDS, (void *)¶m, unused); |
| 59 | } |
| 60 | |
| 61 | uint32_t svc_get_spi_rom_info(struct spirom_info *spi_rom_info) |
| 62 | { |
| 63 | uint32_t retval = 0; |
| 64 | struct cmd_param_spirom_info param = { |
| 65 | .ptr_spirom_info = spi_rom_info, |
| 66 | }; |
| 67 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_GET_SPI_INFO, (void *)¶m, retval); |
| 68 | return retval; |
| 69 | } |
| 70 | |
| 71 | uint32_t svc_map_fch_dev(enum fch_io_device io_device, |
| 72 | uint32_t arg1, uint32_t arg2, void **io_device_axi_addr) |
| 73 | { |
| 74 | uint32_t retval = 0; |
| 75 | struct cmd_param_map_fch_io_device param = { |
| 76 | .io_device = io_device, |
| 77 | .arg1 = arg1, |
| 78 | .arg2 = arg2, |
| 79 | .pptr_io_device_addr_axi = io_device_axi_addr, |
| 80 | }; |
| 81 | assert(io_device < FCH_IO_DEVICE_END); |
| 82 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_MAP_FCH_IO_DEVICE, (void *)¶m, retval); |
| 83 | return retval; |
| 84 | } |
| 85 | |
| 86 | uint32_t svc_unmap_fch_dev(enum fch_io_device io_device, void *io_device_axi_addr) |
| 87 | { |
| 88 | uint32_t retval = 0; |
| 89 | struct cmd_param_unmap_fch_io_device param = { |
| 90 | .io_device = io_device, |
| 91 | .ptr_io_device_addr_axi = io_device_axi_addr, |
| 92 | }; |
| 93 | assert(io_device < FCH_IO_DEVICE_END); |
| 94 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_UNMAP_FCH_IO_DEVICE, (void *)¶m, retval); |
| 95 | return retval; |
| 96 | } |
| 97 | |
| 98 | uint32_t svc_map_spi_rom(void *spi_rom_addr, |
| 99 | uint32_t size, void **spi_rom_axi_addr) |
| 100 | { |
| 101 | uint32_t retval = 0; |
| 102 | struct cmd_param_map_spirom param = { |
| 103 | .spirom_addr = (uintptr_t)spi_rom_addr, |
| 104 | .size = size, |
| 105 | .ppspirom_addr_axi = spi_rom_axi_addr, |
| 106 | }; |
| 107 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_MAP_SPIROM_DEVICE, (void *)¶m, retval); |
| 108 | return retval; |
| 109 | } |
| 110 | |
| 111 | uint32_t svc_unmap_spi_rom(void *spi_rom_addr) |
| 112 | { |
| 113 | uint32_t retval = 0; |
| 114 | struct cmd_param_unmap_spirom param = { |
| 115 | .ptr_spirom_addr_axi = spi_rom_addr, |
| 116 | }; |
| 117 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_UNMAP_SPIROM_DEVICE, (void *)¶m, retval); |
| 118 | return retval; |
| 119 | } |
| 120 | |
| 121 | uint32_t svc_update_psp_bios_dir(uint32_t *psp_dir_offset, |
| 122 | uint32_t *bios_dir_offset) |
| 123 | { |
| 124 | uint32_t retval = 0; |
| 125 | struct cmd_param_psp_update param = { |
| 126 | .ptr_psp_dir_addr = psp_dir_offset, |
| 127 | }; |
| 128 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_UPDATE_PSP_BIOS_DIR, (void *)¶m, retval); |
| 129 | return retval; |
| 130 | } |
| 131 | |
| 132 | uint32_t svc_save_uapp_data(void *address, uint32_t size) |
| 133 | { |
| 134 | uint32_t retval = 0; |
| 135 | struct cmd_param_copy_data_from_uapp param = { |
| 136 | .address = (uintptr_t)address, |
| 137 | .size = size, |
| 138 | }; |
| 139 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_COPY_DATA_FROM_UAPP, (void *)¶m, retval); |
| 140 | return retval; |
| 141 | } |
| 142 | |
| 143 | uint32_t svc_read_timer_val(enum psp_timer_type type, uint64_t *counter_value) |
| 144 | { |
| 145 | unsigned int retval = 0; |
| 146 | struct cmd_param_read_timer_val param = { |
| 147 | .timer_type = type, |
| 148 | .ptr_counter_value = counter_value, |
| 149 | }; |
| 150 | assert(type < PSP_TIMER_TYPE_MAX); |
| 151 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_READ_TIMER_VAL, (void *)¶m, retval); |
| 152 | return retval; |
| 153 | } |
| 154 | |
| 155 | uint32_t svc_reset_system(enum reset_type reset_type) |
| 156 | { |
| 157 | unsigned int retval = 0; |
| 158 | struct cmd_param_reset_system param = { |
| 159 | .reset_type = reset_type, |
| 160 | }; |
| 161 | assert(reset_type < RESET_TYPE_MAX); |
| 162 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_RESET_SYSTEM, (void *)¶m, retval); |
| 163 | return retval; |
| 164 | } |
| 165 | |
| 166 | uint32_t svc_crypto_sha(struct sha_generic_data *sha_op, enum sha_operation_mode sha_mode) |
| 167 | { |
| 168 | uint32_t retval = 0; |
| 169 | struct cmd_param_sha param = { |
| 170 | .ptr_sha_op = sha_op, |
| 171 | }; |
| 172 | assert(sha_mode == SHA_GENERIC); |
| 173 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_SHA, (void *)¶m, retval); |
| 174 | return retval; |
| 175 | } |
| 176 | |
| 177 | uint32_t svc_modexp(struct mod_exp_params *mod_exp_param) |
| 178 | { |
| 179 | uint32_t retval = 0; |
| 180 | struct cmd_param_modexp param = { |
| 181 | .ptr_modexp = mod_exp_param, |
| 182 | }; |
| 183 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_MODEXP, (void *)¶m, retval); |
| 184 | return retval; |
Martin Roth | f95a11e | 2022-10-21 16:43:08 -0600 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | uint32_t svc_ccp_dma(uint32_t spi_rom_offset, void *dest, uint32_t size) |
| 188 | { |
| 189 | uint32_t retval = 0; |
| 190 | struct cmd_param_ccp_dma param = { |
| 191 | .spi_offset = spi_rom_offset, |
| 192 | .dst_addr = (uintptr_t)dest, |
| 193 | .size = size, |
| 194 | }; |
| 195 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_CCP_DMA, (void *)¶m, retval); |
| 196 | return retval; |
| 197 | } |
| 198 | |
| 199 | uint32_t svc_set_platform_boot_mode(enum chrome_platform_boot_mode boot_mode) |
| 200 | { |
| 201 | uint32_t retval = 0; |
| 202 | struct cmd_param_set_platform_boot_mode param = { |
| 203 | .boot_mode = boot_mode, |
| 204 | }; |
| 205 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_SET_PLATFORM_BOOT_MODE, (void *)¶m, retval); |
| 206 | return retval; |
| 207 | } |
| 208 | |
| 209 | uint32_t svc_set_fw_hash_table(struct psp_fw_hash_table *hash_table) |
| 210 | { |
| 211 | uint32_t retval = 0; |
| 212 | struct cmd_param_set_fw_hash_table param = { |
| 213 | .ptr_psp_fw_hash_table = hash_table, |
| 214 | }; |
| 215 | SVC_CALL2(SVC_VERSTAGE_CMD, CMD_SET_FW_HASH_TABLE, (void *)¶m, retval); |
| 216 | return retval; |
| 217 | } |