Martin Roth | 87bbeac | 2022-10-06 15:52:38 -0600 | [diff] [blame] | 1 | /***************************************************************************** |
| 2 | * |
| 3 | * Copyright (c) 2022, Advanced Micro Devices, Inc. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * * Neither the name of Advanced Micro Devices, Inc. nor the names of |
| 14 | * its contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY |
| 21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | * |
| 28 | ***************************************************************************/ |
| 29 | |
Martin Roth | 20646cd | 2023-01-04 21:27:06 -0700 | [diff] [blame] | 30 | /* TODO: Update for Phoenix */ |
Martin Roth | 87bbeac | 2022-10-06 15:52:38 -0600 | [diff] [blame] | 31 | |
| 32 | #ifndef _BL_SYSCALL_PUBLIC_H_ |
| 33 | #define _BL_SYSCALL_PUBLIC_H_ |
| 34 | |
| 35 | #include <stdint.h> |
| 36 | |
| 37 | #define SVC_EXIT 0x00 |
| 38 | #define SVC_ENTER 0x02 |
| 39 | #define SVC_VERSTAGE_CMD 0x3A |
| 40 | |
| 41 | enum verstage_cmd_id { |
| 42 | CMD_SHA = 1, |
| 43 | CMD_MODEXP, |
| 44 | CMD_DEBUG_PRINT, |
| 45 | CMD_DEBUG_PRINT_EX, |
| 46 | CMD_UPDATE_PSP_BIOS_DIR, |
| 47 | CMD_GET_SPI_INFO, |
| 48 | CMD_MAP_SPIROM_DEVICE, |
| 49 | CMD_UNMAP_SPIROM_DEVICE, |
| 50 | CMD_READ_TIMER_VAL, |
| 51 | CMD_DELAY_IN_MICRO_SECONDS, |
| 52 | CMD_RESET_SYSTEM, |
| 53 | CMD_GET_BOOT_MODE, |
| 54 | CMD_COPY_DATA_FROM_UAPP, |
| 55 | CMD_MAP_FCH_IO_DEVICE, |
| 56 | CMD_UNMAP_FCH_IO_DEVICE, |
| 57 | CMD_CCP_DMA, |
| 58 | CMD_SET_PLATFORM_BOOT_MODE, |
| 59 | CMD_SET_FW_HASH_TABLE, |
Karthikeyan Ramasubramanian | 0507e06 | 2023-06-01 14:45:41 -0600 | [diff] [blame] | 60 | CMD_GET_PREV_BOOT_STATUS, |
| 61 | CMD_GET_HSP_SECURE_STATE, |
| 62 | CMD_WRITE_POSTCODE, |
Karthikeyan Ramasubramanian | 2c82843 | 2023-07-14 16:56:04 -0600 | [diff] [blame] | 63 | CMD_SET_FW_HASH_TABLE_STAGE1, |
| 64 | CMD_SET_FW_HASH_TABLE_STAGE2, |
| 65 | CMD_SET_FW_HASH_TABLE_TOS, |
Martin Roth | 87bbeac | 2022-10-06 15:52:38 -0600 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | struct mod_exp_params { |
| 69 | char *pExponent; // Exponent address |
| 70 | unsigned int ExpSize; // Exponent size in bytes |
| 71 | char *pModulus; // Modulus address |
| 72 | unsigned int ModulusSize; // Modulus size in bytes |
| 73 | char *pMessage; // Message address, same size as ModulusSize |
| 74 | char *pOutput; // Output address; Must be big enough to hold the |
| 75 | // data of ModulusSize |
| 76 | }; |
| 77 | |
| 78 | enum psp_boot_mode { |
| 79 | PSP_BOOT_MODE_S0 = 0x0, |
| 80 | PSP_BOOT_MODE_S0i3_RESUME = 0x1, |
| 81 | PSP_BOOT_MODE_S3_RESUME = 0x2, |
| 82 | PSP_BOOT_MODE_S4 = 0x3, |
| 83 | PSP_BOOT_MODE_S5_COLD = 0x4, |
| 84 | PSP_BOOT_MODE_S5_WARM = 0x5, |
| 85 | }; |
| 86 | |
| 87 | enum reset_type |
| 88 | { |
| 89 | RESET_TYPE_COLD = 0, |
| 90 | RESET_TYPE_WARM = 1, |
| 91 | RESET_TYPE_MAX = 2, |
| 92 | }; |
| 93 | |
| 94 | enum fch_io_device { |
| 95 | FCH_IO_DEVICE_SPI, |
| 96 | FCH_IO_DEVICE_I2C, |
| 97 | FCH_IO_DEVICE_GPIO, |
| 98 | FCH_IO_DEVICE_ESPI, |
| 99 | FCH_IO_DEVICE_IOMUX, |
| 100 | FCH_IO_DEVICE_MISC, |
| 101 | FCH_IO_DEVICE_AOAC, |
| 102 | FCH_IO_DEVICE_IOPORT, |
Karthikeyan Ramasubramanian | 0507e06 | 2023-06-01 14:45:41 -0600 | [diff] [blame] | 103 | FCH_IO_DEVICE_UART, |
Martin Roth | 87bbeac | 2022-10-06 15:52:38 -0600 | [diff] [blame] | 104 | FCH_IO_DEVICE_END, |
| 105 | }; |
| 106 | |
| 107 | enum fch_i2c_controller_id { |
| 108 | FCH_I2C_CONTROLLER_ID_0 = 0, |
| 109 | FCH_I2C_CONTROLLER_ID_1 = 1, |
| 110 | FCH_I2C_CONTROLLER_ID_2 = 2, |
| 111 | FCH_I2C_CONTROLLER_ID_3 = 3, |
| 112 | FCH_I2C_CONTROLLER_ID_MAX, |
| 113 | }; |
| 114 | |
Karthikeyan Ramasubramanian | 0507e06 | 2023-06-01 14:45:41 -0600 | [diff] [blame] | 115 | enum fch_uart_id { |
| 116 | FCH_UART_ID_0 = 0, |
| 117 | FCH_UART_ID_1 = 1, |
| 118 | FCH_UART_ID_MAX, |
| 119 | }; |
| 120 | |
Martin Roth | 87bbeac | 2022-10-06 15:52:38 -0600 | [diff] [blame] | 121 | struct spirom_info { |
| 122 | void *SpiBiosSysHubBase; |
| 123 | void *SpiBiosSmnBase; |
| 124 | uint32_t SpiBiosSize; |
| 125 | }; |
| 126 | |
| 127 | enum psp_timer_type { |
| 128 | PSP_TIMER_TYPE_CHRONO = 0, |
| 129 | PSP_TIMER_TYPE_SECURE_RTC = 1, |
| 130 | PSP_TIMER_TYPE_MAX = 2, |
| 131 | }; |
| 132 | |
| 133 | /* SHA types same as ccp SHA type in crypto.h */ |
| 134 | enum sha_type { |
| 135 | SHA_TYPE_256, |
| 136 | SHA_TYPE_384 |
| 137 | }; |
| 138 | |
| 139 | /* All SHA operation supported */ |
| 140 | enum sha_operation_mode { |
| 141 | SHA_GENERIC |
| 142 | }; |
| 143 | |
| 144 | /* SHA Supported Data Structures */ |
| 145 | struct sha_generic_data { |
| 146 | enum sha_type SHAType; |
| 147 | uint8_t *Data; |
| 148 | uint32_t DataLen; |
| 149 | uint32_t DataMemType; |
| 150 | uint8_t *Digest; |
| 151 | uint32_t DigestLen; |
| 152 | uint8_t *IntermediateDigest; |
| 153 | uint32_t IntermediateMsgLen; |
| 154 | uint32_t Init; |
| 155 | uint32_t Eom; |
| 156 | }; |
| 157 | |
| 158 | /* |
| 159 | * This is state that PSP manages internally. |
| 160 | * We only report BOOT_MODE_DEVELOPER or BOOT_MODE_NORMAL in verstage. |
| 161 | */ |
| 162 | enum chrome_platform_boot_mode |
| 163 | { |
| 164 | NON_CHROME_BOOK_BOOT_MODE = 0x0, |
| 165 | CHROME_BOOK_BOOT_MODE_UNSIGNED_VERSTAGE = 0x1, |
| 166 | CHROME_BOOK_BOOT_MODE_NORMAL = 0x2, |
| 167 | CHROME_BOOK_BOOT_MODE_DEVELOPER = 0x3, |
| 168 | CHROME_BOOK_BOOT_MODE_TYPE_MAX_LIMIT = 0x4, // used for boundary check |
| 169 | }; |
| 170 | |
| 171 | struct psp_fw_entry_hash_256 { |
| 172 | uint16_t fw_type; |
| 173 | uint16_t sub_type; |
| 174 | uint8_t sha[32]; |
| 175 | } __packed; |
| 176 | |
| 177 | struct psp_fw_entry_hash_384 { |
| 178 | uint16_t fw_type; |
| 179 | uint16_t sub_type; |
| 180 | uint8_t sha[48]; |
| 181 | } __packed; |
| 182 | |
| 183 | struct psp_fw_hash_table { |
Karthikeyan Ramasubramanian | 2c82843 | 2023-07-14 16:56:04 -0600 | [diff] [blame] | 184 | uint16_t version; // Version 1 of psp_fw_hash_table. |
Martin Roth | 87bbeac | 2022-10-06 15:52:38 -0600 | [diff] [blame] | 185 | uint16_t no_of_entries_256; |
| 186 | uint16_t no_of_entries_384; |
| 187 | struct psp_fw_entry_hash_256 *fw_hash_256; |
| 188 | struct psp_fw_entry_hash_384 *fw_hash_384; |
| 189 | } __packed; |
| 190 | |
Karthikeyan Ramasubramanian | 2c82843 | 2023-07-14 16:56:04 -0600 | [diff] [blame] | 191 | struct psp_fw_entry_hash_256_v2 { |
| 192 | uint8_t uuid[16]; |
| 193 | uint8_t sha[32]; |
| 194 | } __packed; |
| 195 | |
| 196 | struct psp_fw_entry_hash_384_v2 { |
| 197 | uint8_t uuid[16]; |
| 198 | uint8_t sha[48]; |
| 199 | } __packed; |
| 200 | |
| 201 | struct psp_fw_hash_table_v2 { |
| 202 | uint16_t version; // Version 2 of psp_fw_hash_table. |
| 203 | uint16_t no_of_entries_256; |
| 204 | uint16_t no_of_entries_384; |
| 205 | uint16_t reserved; // For alignment purposes. |
| 206 | struct psp_fw_entry_hash_256_v2 *fw_hash_256; |
| 207 | struct psp_fw_entry_hash_384_v2 *fw_hash_384; |
| 208 | } __packed; |
| 209 | |
Martin Roth | 87bbeac | 2022-10-06 15:52:38 -0600 | [diff] [blame] | 210 | /* |
| 211 | * Exit to the main Boot Loader. This does not return back to user application. |
| 212 | * |
| 213 | * Parameters: |
| 214 | * status - either Ok or error code defined by AGESA |
| 215 | */ |
| 216 | void svc_exit(uint32_t status); |
| 217 | |
| 218 | /* Print debug message into serial console. |
| 219 | * |
| 220 | * Parameters: |
| 221 | * string - null-terminated string |
| 222 | */ |
| 223 | void svc_debug_print(const char *string); |
| 224 | |
| 225 | /* Print 4 DWORD values in hex to serial console |
| 226 | * |
| 227 | * Parameters: |
| 228 | * dword0...dword3 - 32-bit DWORD to print |
| 229 | */ |
| 230 | void svc_debug_print_ex(uint32_t dword0, |
| 231 | uint32_t dword1, uint32_t dword2, uint32_t dword3); |
| 232 | |
| 233 | /* Description - Returns the current boot mode from the enum psp_boot_mode found in |
| 234 | * bl_public.h. |
| 235 | * |
| 236 | * Inputs - boot_mode - Output parameter passed in R0 |
| 237 | * |
| 238 | * Outputs - The boot mode in boot_mode. |
| 239 | * See Return Values. |
| 240 | * |
| 241 | * Return Values - BL_OK |
| 242 | * BL_ERR_NULL_PTR |
| 243 | * Other BL_ERRORs lofted up from called functions |
| 244 | */ |
| 245 | uint32_t svc_get_boot_mode(uint32_t *boot_mode); |
| 246 | |
| 247 | /* Add delay in micro seconds |
| 248 | * |
| 249 | * Parameters: |
| 250 | * delay - required delay value in microseconds |
| 251 | * |
| 252 | * Return value: NONE |
| 253 | */ |
| 254 | void svc_delay_in_usec(uint32_t delay); |
| 255 | |
| 256 | /* Get the SPI-ROM information |
| 257 | * |
| 258 | * Parameters: |
| 259 | * spi_rom_iInfo - SPI-ROM information |
| 260 | * |
| 261 | * Return value: BL_OK or error code |
| 262 | */ |
| 263 | uint32_t svc_get_spi_rom_info(struct spirom_info *spi_rom_info); |
| 264 | |
| 265 | /* Map the FCH IO device register space (SPI/I2C/GPIO/eSPI/etc...) |
| 266 | * |
| 267 | * Parameters: |
| 268 | * io_device - ID for respective FCH IO controller register space to be mapped |
| 269 | * arg1 - Based on IODevice ID, interpretation of this argument changes. |
| 270 | * arg2 - Based on IODevice ID, interpretation of this argument changes. |
| 271 | * io_device_axi_addr - AXI address for respective FCH IO device register space |
| 272 | * |
| 273 | * Return value: BL_OK or error code |
| 274 | */ |
| 275 | uint32_t svc_map_fch_dev(enum fch_io_device io_device, |
| 276 | uint32_t arg1, uint32_t arg2, void **io_device_axi_addr); |
| 277 | |
| 278 | /* Unmap the FCH IO device register space mapped earlier using Svc_MapFchIODevice() |
| 279 | * |
| 280 | * Parameters: |
| 281 | * io_device - ID for respective FCH IO controller register space to be unmapped |
| 282 | * io_device_addr - AXI address for respective FCH IO device register space |
| 283 | * |
| 284 | * Return value: BL_OK or error code |
| 285 | */ |
| 286 | uint32_t svc_unmap_fch_dev(enum fch_io_device io_device, |
| 287 | void *io_device_axi_addr); |
| 288 | |
| 289 | /* Map the SPIROM FLASH device address space |
| 290 | * |
| 291 | * Parameters: |
| 292 | * SpiRomAddr - Address in SPIROM tobe mapped (SMN based) |
| 293 | * size - Size to be mapped |
| 294 | * pSpiRomAddrAxi - Mapped address in AXI space |
| 295 | * |
| 296 | * Return value: BL_OK or error code |
| 297 | */ |
| 298 | uint32_t svc_map_spi_rom(void *spi_rom_addr, |
| 299 | uint32_t size, void **spi_rom_axi_addr); |
| 300 | |
| 301 | /* Unmap the SPIROM FLASH device address space mapped earlier using Svc_MapSpiRomDevice() |
| 302 | * |
| 303 | * Parameters: |
| 304 | * pSpiRomAddrAxi - Address in AXI address space previously mapped |
| 305 | * |
| 306 | * Return value: BL_OK or error code |
| 307 | */ |
| 308 | uint32_t svc_unmap_spi_rom(void *spi_rom_addr); |
| 309 | |
| 310 | /* Updates the offset at which PSP or BIOS Directory can be found in the |
| 311 | * SPI flash |
| 312 | * |
| 313 | * Parameters: |
| 314 | * psp_dir_offset - [in/out] Offset at which PSP Directory can be |
| 315 | * found in the SPI Flash. Same pointer is used |
| 316 | * to return the offset in case of GET operation |
| 317 | * bios_dir_offset - [in/out] Offset at which BIOS Directory can be |
| 318 | * found in the SPI Flash. Same pointer is used |
| 319 | * to return the offset in case of GET operation |
| 320 | * |
| 321 | * Return value: BL_OK or error code |
| 322 | */ |
| 323 | uint32_t svc_update_psp_bios_dir(uint32_t *psp_dir_offset, |
| 324 | uint32_t *bios_dir_offset); |
| 325 | |
| 326 | /* Copies the data that is shared by verstage to the PSP BL owned memory |
| 327 | * |
| 328 | * Parameters: |
| 329 | * address - Address in UAPP controlled/owned memory |
| 330 | * size - Total size of memory to copy (max 16Kbytes) |
| 331 | */ |
| 332 | uint32_t svc_save_uapp_data(void *address, uint32_t size); |
| 333 | |
| 334 | /* |
| 335 | * Read timer raw (currently CHRONO and RTC) value |
| 336 | * |
| 337 | * Parameters: |
| 338 | * type - [in] Type of timer UAPP would like to read from |
| 339 | * (currently CHRONO and RTC) |
| 340 | * counter_value - [out] return the raw counter value read from |
| 341 | * RTC or CHRONO_LO/HI counter register |
| 342 | -----------------------------------------------------------------------------*/ |
| 343 | uint32_t svc_read_timer_val(enum psp_timer_type type, uint64_t *counter_value); |
| 344 | |
| 345 | /* |
| 346 | * Reset the system |
| 347 | * |
| 348 | * Parameters: |
| 349 | * reset_type - Cold or Warm reset |
| 350 | */ |
| 351 | uint32_t svc_reset_system(enum reset_type reset_type); |
| 352 | |
| 353 | /* |
| 354 | * Write postcode to Port-80 |
| 355 | * |
| 356 | * Parameters: |
| 357 | * postcode - Postcode value to be written on port-80h |
| 358 | */ |
| 359 | uint32_t svc_write_postcode(uint32_t postcode); |
| 360 | |
| 361 | /* |
| 362 | * Generic SHA call for SHA, SHA_OTP, SHA_HMAC |
| 363 | */ |
| 364 | uint32_t svc_crypto_sha(struct sha_generic_data *sha_op, enum sha_operation_mode sha_mode); |
| 365 | |
| 366 | /* |
| 367 | * Calculate ModEx |
| 368 | * |
| 369 | * Parameters: |
| 370 | * mod_exp_param - ModExp parameters |
| 371 | * |
| 372 | * Return value: BL_OK or error code |
| 373 | */ |
| 374 | uint32_t svc_modexp(struct mod_exp_params *mod_exp_param); |
| 375 | |
| 376 | /* |
| 377 | * Copies the data from source to destination using ccp |
| 378 | * |
| 379 | * Parameters: |
| 380 | * Source Address - SPI ROM offset |
| 381 | * Destination Address - Address in Verstage memory |
| 382 | * Size - Total size to copy |
| 383 | * |
| 384 | * Return value: BL_OK or error code |
| 385 | */ |
| 386 | uint32_t svc_ccp_dma(uint32_t spi_rom_offset, void *dest, uint32_t size); |
| 387 | |
| 388 | /* |
| 389 | * Get the Platform boot mode from verstage. Normal or developer |
| 390 | * |
| 391 | * Parameters: |
| 392 | * - boot mode |
| 393 | -----------------------------------------------------------------------------*/ |
| 394 | uint32_t svc_set_platform_boot_mode(enum chrome_platform_boot_mode boot_mode); |
| 395 | |
| 396 | /* |
Karthikeyan Ramasubramanian | 2c82843 | 2023-07-14 16:56:04 -0600 | [diff] [blame] | 397 | * Set PSP FW hash table. |
Martin Roth | 87bbeac | 2022-10-06 15:52:38 -0600 | [diff] [blame] | 398 | * |
| 399 | * Parameters: |
| 400 | * - hash_table - Table of hash for each PSP binary signed against SoC chain of trust |
Karthikeyan Ramasubramanian | 2c82843 | 2023-07-14 16:56:04 -0600 | [diff] [blame] | 401 | * - cmd - Cmd to indicate the PSP stage using the hash table |
Martin Roth | 87bbeac | 2022-10-06 15:52:38 -0600 | [diff] [blame] | 402 | * |
| 403 | * Return value: BL_OK or error code |
| 404 | */ |
Karthikeyan Ramasubramanian | 2c82843 | 2023-07-14 16:56:04 -0600 | [diff] [blame] | 405 | uint32_t svc_set_fw_hash_table(enum verstage_cmd_id cmd, void *hash_table); |
Martin Roth | 87bbeac | 2022-10-06 15:52:38 -0600 | [diff] [blame] | 406 | |
Karthikeyan Ramasubramanian | 0507e06 | 2023-06-01 14:45:41 -0600 | [diff] [blame] | 407 | /* Get the previous boot status. |
| 408 | * |
| 409 | * Parameters: |
| 410 | * - boot_status - Address where the boot status is read into |
| 411 | * |
| 412 | * Return value: BL_OK or error code |
| 413 | */ |
| 414 | uint32_t svc_get_prev_boot_status(uint32_t *boot_status); |
| 415 | |
| 416 | /* Get HSP Secure state |
| 417 | * |
| 418 | * Parameters: |
| 419 | * - hsp_secure_state - Address where the state info is read into |
| 420 | * |
| 421 | * Return value: BL_OK or error code |
| 422 | */ |
| 423 | uint32_t svc_get_hsp_secure_state(uint32_t *hsp_secure_state); |
| 424 | |
Martin Roth | 87bbeac | 2022-10-06 15:52:38 -0600 | [diff] [blame] | 425 | /* C entry point for the Bootloader Userspace Application */ |
| 426 | void Main(void); |
| 427 | |
| 428 | #endif /* _BL_SYSCALL__PUBLIC_H_ */ |